Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-07-07 22:40:54 -04:00
parent ea7c18723f
commit c57c41ade0
10 changed files with 74 additions and 33 deletions

View File

@ -52,10 +52,10 @@ android {
compileSdkVersion 29 compileSdkVersion 29
defaultConfig { defaultConfig {
applicationId "website.christine.xesite" applicationId "website.christine.xesite"
minSdkVersion 19 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 6 versionCode 8
versionName "1.1.0.0" versionName "1.1.1.1"
// The name for the application // The name for the application
resValue "string", "appName", twaManifest.name resValue "string", "appName", twaManifest.name
@ -153,6 +153,9 @@ android {
buildFeatures { buildFeatures {
viewBinding true viewBinding true
} }
kotlinOptions {
jvmTarget = '1.8'
}
} }
task generateShorcutsFile { task generateShorcutsFile {
@ -203,4 +206,9 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.7' implementation 'com.google.code.gson:gson:2.8.7'
implementation 'com.google.androidbrowserhelper:locationdelegation:1.0.0' implementation 'com.google.androidbrowserhelper:locationdelegation:1.0.0'
implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.2.0' implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
} }

View File

@ -12,6 +12,7 @@
android:manageSpaceActivity="com.google.androidbrowserhelper.trusted.ManageDataLauncherActivity" android:manageSpaceActivity="com.google.androidbrowserhelper.trusted.ManageDataLauncherActivity"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar"> android:theme="@android:style/Theme.Translucent.NoTitleBar">
<receiver android:name=".NewPostWidget"> <receiver android:name=".NewPostWidget">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
@ -94,7 +95,7 @@
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<data <data
android:host="@string/hostName" android:host="christine.website"
android:scheme="https" /> android:scheme="https" />
</intent-filter> </intent-filter>
</activity> </activity>

View File

@ -49,4 +49,3 @@ class Application : Application() {
internal val NEW_POST_CHANNEL = "New Posts"; internal val NEW_POST_CHANNEL = "New Posts";
internal val NEW_POST_CHANNEL_DESC = "New posts on christine.website"; internal val NEW_POST_CHANNEL_DESC = "New posts on christine.website";
internal val notificationId = 1;

View File

@ -15,13 +15,6 @@
*/ */
package website.christine.xesite package website.christine.xesite
import android.content.Context
import android.net.Uri
import com.google.androidbrowserhelper.trusted.LauncherActivity import com.google.androidbrowserhelper.trusted.LauncherActivity
class LauncherActivity : LauncherActivity() { class LauncherActivity : LauncherActivity() {}
override fun getLaunchingUrl(): Uri {
// Get the original launch Url.
return super.getLaunchingUrl()
}
}

View File

@ -1,11 +1,11 @@
package website.christine.xesite package website.christine.xesite
import android.app.NotificationChannel import android.app.PendingIntent
import android.app.NotificationManager
import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider import android.appwidget.AppWidgetProvider
import android.content.Context import android.content.Context
import android.os.Build import android.content.Intent
import android.net.Uri
import android.util.Log import android.util.Log
import android.widget.RemoteViews import android.widget.RemoteViews
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
@ -15,6 +15,7 @@ import com.android.volley.Response
import com.android.volley.toolbox.BasicNetwork import com.android.volley.toolbox.BasicNetwork
import com.android.volley.toolbox.DiskBasedCache import com.android.volley.toolbox.DiskBasedCache
import com.android.volley.toolbox.HurlStack import com.android.volley.toolbox.HurlStack
import java.util.concurrent.ThreadLocalRandom
/** /**
* Implementation of App Widget functionality. * Implementation of App Widget functionality.
@ -26,17 +27,22 @@ class NewPostWidget : AppWidgetProvider() {
val pkgInfo = ctx.getPackageManager().getPackageInfo(ctx.packageName, 0) val pkgInfo = ctx.getPackageManager().getPackageInfo(ctx.packageName, 0)
return ctx.packageName.plus("/").plus(pkgInfo.versionName) return ctx.packageName.plus("/").plus(pkgInfo.versionName)
.plus("(android; +https://christine.website/contact)")
} }
private fun notify(ctx: Context, newPost: NewPost) { private fun notify(ctx: Context, newPost: NewPost) {
val notificationIntent = Intent(Intent.ACTION_VIEW, Uri.parse(newPost.link))
val pendingIntent: PendingIntent = PendingIntent.getActivity(ctx, 0, notificationIntent, 0)
var builder = NotificationCompat.Builder(ctx, NEW_POST_CHANNEL) var builder = NotificationCompat.Builder(ctx, NEW_POST_CHANNEL)
.setSmallIcon(R.drawable.splash) .setSmallIcon(R.drawable.splash)
.setContentIntent(pendingIntent)
.setContentTitle(newPost.title) .setContentTitle(newPost.title)
.setContentText(newPost.summary) .setContentText(newPost.summary)
.setPriority(NotificationCompat.PRIORITY_DEFAULT) .setPriority(NotificationCompat.PRIORITY_DEFAULT)
NotificationManagerCompat.from(ctx).apply { NotificationManagerCompat.from(ctx).apply {
notify(notificationId, builder.build()) notify(ThreadLocalRandom.current().nextInt(), builder.build())
} }
} }
@ -64,7 +70,7 @@ class NewPostWidget : AppWidgetProvider() {
Log.println(Log.INFO, "new_post", response.toString()) Log.println(Log.INFO, "new_post", response.toString())
// There may be multiple widgets active, so update all of them // There may be multiple widgets active, so update all of them
for (appWidgetId in appWidgetIds) { appWidgetIds.forEach { appWidgetId ->
this.updateAppWidget(ctx, appWidgetManager, appWidgetId, response) this.updateAppWidget(ctx, appWidgetManager, appWidgetId, response)
} }
}, Response.ErrorListener { error -> }, Response.ErrorListener { error ->
@ -99,32 +105,41 @@ class NewPostWidget : AppWidgetProvider() {
override fun onEnabled(ctx: Context) { override fun onEnabled(ctx: Context) {
this.makeQueue(ctx) this.makeQueue(ctx)
//this.createNotificationChannel(ctx)
savePref(ctx, "old_url", "http://google.com")
} }
override fun onDisabled(context: Context) { override fun onDisabled(context: Context) {
// Enter relevant functionality for when the last widget is disabled // Enter relevant functionality for when the last widget is disabled
} }
override fun onReceive(ctx: Context?, intent: Intent?) {
super.onReceive(ctx, intent)
}
private fun updateAppWidget( private fun updateAppWidget(
context: Context, ctx: Context,
appWidgetManager: AppWidgetManager, appWidgetManager: AppWidgetManager,
appWidgetId: Int, appWidgetId: Int,
body: NewPost body: NewPost
) { ) {
// Construct the RemoteViews object // Construct the RemoteViews object
val views = RemoteViews(context.packageName, R.layout.new_post_widget) val views = RemoteViews(ctx.packageName, R.layout.new_post_widget)
views.setTextViewText( views.setTextViewText(
R.id.article_title, R.id.article_title,
body.title body.title
) )
views.setTextViewText( views.setTextViewText(
R.id.article_preview, R.id.article_preview,
body.summary body.summary
) )
val pendingIntent: PendingIntent = Intent(Intent.ACTION_VIEW, Uri.parse(body.link))
.let { intent ->
PendingIntent.getActivity(ctx, 0, intent, 0)
}
views.setOnClickPendingIntent(R.id.widget_parent, pendingIntent)
// Instruct the widget manager to update the widget // Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views) appWidgetManager.updateAppWidget(appWidgetId, views)
} }

View File

@ -8,6 +8,7 @@
android:theme="@style/ThemeOverlay.Xesite_android.AppWidgetContainer"> android:theme="@style/ThemeOverlay.Xesite_android.AppWidgetContainer">
<LinearLayout <LinearLayout
android:id="@+id/widget_parent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
@ -15,24 +16,28 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="109dp" android:layout_height="174dp"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imageView"
android:layout_width="92dp" android:layout_width="92dp"
android:layout_height="75dp" android:layout_height="75dp"
android:src="@drawable/splash" android:layout_marginStart="0dp"
android:contentDescription="Logo" /> android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="0dp"
android:contentDescription="Logo"
android:src="@drawable/splash" />
<TextView <TextView
android:id="@+id/article_title" android:id="@+id/article_title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="0dp"
android:layout_marginTop="8dp" android:layout_marginTop="0dp"
android:layout_marginEnd="0dp" android:layout_marginEnd="0dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="0dp"
android:background="@color/gruvbox_dark_bg" android:background="@color/gruvbox_dark_bg"
android:contentDescription="@string/appwidget_title" android:contentDescription="@string/appwidget_title"
android:text="@string/appwidget_title" android:text="@string/appwidget_title"
@ -45,16 +50,16 @@
<TextView <TextView
android:id="@+id/article_preview" android:id="@+id/article_preview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="117dp" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="0dp" android:layout_marginTop="0dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:background="@color/gruvbox_dark_bg" android:background="@color/gruvbox_dark_bg"
android:contentDescription="@string/appwidget_body_preview" android:contentDescription="@string/appwidget_body_preview"
android:text="@string/appwidget_body_preview"
android:scrollHorizontally="true"
android:ellipsize="end" android:ellipsize="end"
android:scrollHorizontally="true"
android:text="@string/appwidget_body_preview"
android:textColor="@color/gruvbox_dark_fg" android:textColor="@color/gruvbox_dark_fg"
android:textSize="16sp" /> android:textSize="16sp" />

View File

@ -6,5 +6,6 @@ Refer to App Widget Documentation for margin information
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
--> -->
<dimen name="widget_margin">0dp</dimen> <dimen name="widget_margin">0dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources> </resources>

View File

@ -5,4 +5,14 @@
<string name="add_widget">Add widget</string> <string name="add_widget">Add widget</string>
<string name="new_post_channel_name">New Posts</string> <string name="new_post_channel_name">New Posts</string>
<string name="new_post_channel_desc">Brand new posts on christine.website</string> <string name="new_post_channel_desc">Brand new posts on christine.website</string>
<string name="title_activity_test">TestActivity</string>
<!-- Strings used for fragments for navigation -->
<string name="first_fragment_label">First Fragment</string>
<string name="second_fragment_label">Second Fragment</string>
<string name="next">Next</string>
<string name="previous">Previous</string>
<string name="logo_description">Logo</string>
<string name="hello_first_fragment">Hello first fragment</string>
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
</resources> </resources>

View File

@ -4,4 +4,13 @@
<item name="appWidgetBackgroundColor">@color/gruvbox_dark_bg</item> <item name="appWidgetBackgroundColor">@color/gruvbox_dark_bg</item>
<item name="appWidgetTextColor">@color/gruvbox_dark_fg</item> <item name="appWidgetTextColor">@color/gruvbox_dark_fg</item>
</style> </style>
<style name="NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources> </resources>

View File

@ -3,7 +3,7 @@
android:initialKeyguardLayout="@layout/new_post_widget" android:initialKeyguardLayout="@layout/new_post_widget"
android:initialLayout="@layout/new_post_widget" android:initialLayout="@layout/new_post_widget"
android:minWidth="250dp" android:minWidth="250dp"
android:minHeight="80dp" android:minHeight="40dp"
android:previewImage="@drawable/example_appwidget_preview" android:previewImage="@drawable/example_appwidget_preview"
android:resizeMode="horizontal|vertical" android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="28800000" android:updatePeriodMillis="28800000"