add styling and investigate data race condition

This commit is contained in:
caleb 2019-09-03 19:56:20 -06:00
parent ea8f9cfe07
commit 155deb7059
8 changed files with 26 additions and 37 deletions

View file

@ -2,20 +2,4 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="@string/select_feed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="@string/select_feed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_select" />
<Button
android:text="@string/save_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_save" />
</LinearLayout>

View file

@ -7,6 +7,8 @@
android:id="@+id/newsblur_widget_item_title"
android:paddingBottom="7dp"
android:paddingTop="7dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:ellipsize="end"
android:lines="1"
android:textSize="14sp"

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="40dp"
android:minWidth="130dp"
android:minHeight="40dp"
android:updatePeriodMillis="86400000"
android:initialLayout="@layout/newsblur_widget"

View file

@ -1,9 +1,11 @@
package com.newsblur.activity;
import android.appwidget.AppWidgetManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
import com.newsblur.R;
import com.newsblur.util.FeedUtils;
import com.newsblur.util.PrefsUtils;
import com.newsblur.util.PrefConstants.ThemeValue;

View file

@ -1122,6 +1122,9 @@ public class BlurDatabaseHelper {
q.append(DatabaseConstants.STORY_FEED_ID);
q.append(" = ");
q.append(fs.getSingleFeed());
q.append(" ORDER BY ");
q.append(DatabaseConstants.STORY_TIMESTAMP);
q.append(" DESC LIMIT 10");
return rawQuery(q.toString(), null, cancellationSignal);
}

View file

@ -3,6 +3,8 @@ package com.newsblur.service;
import android.app.Service;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
@ -37,6 +39,7 @@ import com.newsblur.util.ReadingAction;
import com.newsblur.util.ReadFilter;
import com.newsblur.util.StateFilter;
import com.newsblur.util.StoryOrder;
import com.newsblur.widget.NewsBlurWidgetProvider;
import java.util.ArrayList;
import java.util.Date;

View file

@ -71,6 +71,9 @@ class BlurWidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsFact
}
private void setUpCursor(){
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
cursor = null;
Loader<Cursor> loader = FeedUtils.dbHelper.getStoriesLoader(fs);
loader.registerListener(loader.getId(), new Loader.OnLoadCompleteListener<Cursor>() {
@ -97,12 +100,16 @@ class BlurWidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsFact
s.bindExternValues(cursor);
loadedStories.add(s);
}
// loadedStories.equals()
storyItems.clear();
storyItems.addAll(loadedStories);
cursor.close();
AppWidgetManager.getInstance(context)
.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_list);
// AppWidgetManager widgetManager = AppWidgetManager.getInstance(this);
// int [] widgetIds = widgetManager.getAppWidgetIds(new ComponentName(this, NewsBlurWidgetProvider.class));
// widgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.widget_list);
}
/**
* allowed to run synchronous calls
@ -176,7 +183,8 @@ class BlurWidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsFact
@Override
public void onDataSetChanged() {
// fetch any new data
loadStories(10);
// loadStories(10);
setUpCursor();
Log.d(TAG, "onDataSetChanged");
}
@ -196,7 +204,7 @@ class BlurWidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsFact
*/
@Override
public int getCount() {
Log.d(TAG, "getCount");
Log.d(TAG, "getCount: " + Math.min(storyItems.size(), 10));
return Math.min(storyItems.size(), 10);
}
}

View file

@ -39,7 +39,7 @@ public class ConfigureWidgetActivity extends NbActivity {
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_configure_widget);
PrefsUtils.applyThemePreference(this);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
@ -49,21 +49,7 @@ public class ConfigureWidgetActivity extends NbActivity {
}
Button btnSelect = findViewById(R.id.btn_select);
btnSelect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getAllFeeds();
}
});
Button btnSaveWidget = findViewById(R.id.btn_save);
btnSaveWidget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveWidget();
}
});
getAllFeeds();
// set result as cancelled in the case that we don't finish config
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
@ -106,6 +92,7 @@ public class ConfigureWidgetActivity extends NbActivity {
public void onClick(DialogInterface dialog, int which) {
Log.d(TAG, "Clicked " + which);
selectedFeed = feeds.get(which);
saveWidget();
}
});
builder.create().show();