Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Walz committed Nov 3, 2014
1 parent ecd3736 commit 5024093
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
3 changes: 3 additions & 0 deletions src/de/cwalz/android/woltlabVendor/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public void onCreate(Bundle savedInstanceState) {
currency = settings.getString("currency", "EUR");

datasource = new TransactionsDataSource(this);
datasource.open();
transactions.addAll(datasource.getList());
datasource.close();

transactionsAdapter = new TransactionsAdapter(this, R.layout.transaction_list, transactions);
setListAdapter(transactionsAdapter);
Expand Down
19 changes: 12 additions & 7 deletions src/de/cwalz/android/woltlabVendor/WidgetConfigure.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public void onClick(View arg0) {
boolean vibration = vibrationView.isChecked();

if (vendorID == 0 || apiKey.isEmpty() || currency.isEmpty()) {
Toast.makeText(getApplicationContext(), getString(R.string.emptyForm), Toast.LENGTH_SHORT).show();
Toast.makeText(WidgetConfigure.this, getString(R.string.emptyForm), Toast.LENGTH_SHORT).show();
}
else {
// save new values in preferences
SharedPreferences settings = getApplicationContext().getSharedPreferences(WidgetProvider.PREFS_NAME, 0);
SharedPreferences settings = WidgetConfigure.this.getSharedPreferences(WidgetProvider.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("vendorID", vendorID);
editor.putString("apiKey", apiKey);
Expand All @@ -90,12 +90,17 @@ public void onClick(View arg0) {
editor.commit();

// save new alarm
AlarmUtil.start(WidgetProvider.ALARM_ID, interval, getApplicationContext());
AlarmUtil.start(WidgetProvider.ALARM_ID, interval, WidgetConfigure.this);

Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
// Push widget update to surface with newly set prefix
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(WidgetConfigure.this);
WidgetProvider.updateAppWidget(WidgetConfigure.this, appWidgetManager, new int[] {mAppWidgetId});

// Make sure we pass back the original appWidgetId
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}

}
Expand Down
33 changes: 17 additions & 16 deletions src/de/cwalz/android/woltlabVendor/WidgetProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,27 @@ public class WidgetProvider extends AppWidgetProvider {

public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);

// return if no network is available
if (!NetworkUtil.hasInternetConnection(context)) {
return;
}

for (int appWidgetID : appWidgetIds) {
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.layoutContainer, pendingIntent);

// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetID, views);
updateAppWidget(context, appWidgetManager, appWidgetIds);
}

public static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
for (int appWidgetID : appWidgetIds) {
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.layoutContainer, pendingIntent);

// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetID, views);
}
SharedPreferences settings = context.getSharedPreferences(WidgetProvider.PREFS_NAME, 0);
final int vendorID = settings.getInt("vendorID", 0);
final String apiKey = settings.getString("apiKey", "");
Expand Down

0 comments on commit 5024093

Please sign in to comment.