-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #122; Implement compact "Add Transaction" widget
- Loading branch information
Iliyan Germanov
committed
Nov 16, 2021
1 parent
0c25f38
commit deaac47
Showing
8 changed files
with
160 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/ivy/wallet/widget/AddTransactionWidgetCompact.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.ivy.wallet.widget | ||
|
||
import android.appwidget.AppWidgetManager | ||
import android.appwidget.AppWidgetProvider | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.widget.RemoteViews | ||
import com.ivy.wallet.R | ||
|
||
class AddTransactionWidgetCompact : AppWidgetProvider() { | ||
|
||
companion object { | ||
fun updateBroadcast(context: Context) { | ||
WidgetBase.updateBroadcast(context, AddTransactionWidgetCompact::class.java) | ||
} | ||
} | ||
|
||
override fun onEnabled(context: Context) { | ||
super.onEnabled(context) | ||
updateBroadcast(context) | ||
} | ||
|
||
//--------------------------- </BROADCASTS> ---------------------------------------------------- | ||
override fun onUpdate( | ||
context: Context, | ||
appWidgetManager: AppWidgetManager, | ||
appWidgetIds: IntArray | ||
) { | ||
for (appWidgetId in appWidgetIds) { | ||
updateAppWidget(context, appWidgetManager, appWidgetId) | ||
} | ||
} | ||
|
||
private fun updateAppWidget( | ||
context: Context, | ||
appWidgetManager: AppWidgetManager, | ||
appWidgetId: Int | ||
) { | ||
val rv = RemoteViews(context.packageName, R.layout.widget_add_transaction_compact) | ||
val clickSetup = AddTransactionWidgetClick.Setup(context, rv, appWidgetId) | ||
|
||
clickSetup.clickListener(R.id.ivIncome, AddTransactionWidgetClick.ACTION_ADD_INCOME) | ||
|
||
clickSetup.clickListener(R.id.ivExpense, AddTransactionWidgetClick.ACTION_ADD_EXPENSE) | ||
|
||
clickSetup.clickListener(R.id.ivTransfer, AddTransactionWidgetClick.ACTION_ADD_TRANSFER) | ||
|
||
appWidgetManager.updateAppWidget(appWidgetId, rv) | ||
} | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
super.onReceive(context, intent) | ||
val widgetClick = AddTransactionWidgetClick() | ||
widgetClick.handleClick(context, intent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.ivy.wallet.widget | ||
|
||
import android.appwidget.AppWidgetManager | ||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.content.Intent | ||
import timber.log.Timber | ||
|
||
class WidgetBase { | ||
companion object { | ||
fun <T> updateBroadcast(context: Context, widget: Class<T>) { | ||
Timber.d("update()") | ||
val intent = Intent(context, widget) | ||
intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE | ||
val appWidgetManager = AppWidgetManager.getInstance(context) | ||
intent.putExtra( | ||
AppWidgetManager.EXTRA_APPWIDGET_IDS, | ||
getAppWidgetIds( | ||
context = context, | ||
appWidgetManager = appWidgetManager, | ||
widget = widget | ||
) | ||
) | ||
context.sendBroadcast(intent) | ||
} | ||
|
||
private fun <T> getAppWidgetIds( | ||
context: Context, | ||
appWidgetManager: AppWidgetManager, | ||
widget: Class<T> | ||
): IntArray? { | ||
val ivyWidgetComponent = | ||
ComponentName(context, widget) | ||
return appWidgetManager.getAppWidgetIds(ivyWidgetComponent) | ||
} | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions
48
app/src/main/res/layout/widget_add_transaction_compact.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/rlWidgetRoot" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="center" | ||
android:gravity="center" | ||
android:orientation="horizontal" | ||
tools:background="@color/white"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_vertical" | ||
android:background="@drawable/shape_widget_background" | ||
android:orientation="horizontal" | ||
android:paddingLeft="16dp" | ||
android:paddingTop="12dp" | ||
android:paddingRight="16dp" | ||
android:paddingBottom="14dp"> | ||
|
||
|
||
<ImageView | ||
android:id="@+id/ivIncome" | ||
android:layout_width="0dp" | ||
android:layout_weight="1" | ||
android:layout_height="48dp" | ||
android:src="@drawable/ic_widget_income" /> | ||
|
||
|
||
<ImageView | ||
android:id="@+id/ivExpense" | ||
android:layout_width="0dp" | ||
android:layout_weight="1" | ||
android:layout_height="48dp" | ||
android:src="@drawable/ic_widget_expense" /> | ||
|
||
|
||
<ImageView | ||
android:id="@+id/ivTransfer" | ||
android:layout_width="0dp" | ||
android:layout_weight="1" | ||
android:layout_height="48dp" | ||
android:src="@drawable/ic_widget_transfer" /> | ||
</LinearLayout> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:initialLayout="@layout/widget_add_transaction" | ||
android:minWidth="110dp" | ||
android:minResizeWidth="40dp" | ||
android:previewImage="@drawable/preview_widget_add_trn_compact" | ||
android:resizeMode="horizontal|vertical" | ||
android:updatePeriodMillis="0" /> |
File renamed without changes.