mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Android widget config feed list updates
This commit is contained in:
parent
e0cbdbfd35
commit
87338fd02d
3 changed files with 44 additions and 41 deletions
|
@ -1,31 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_no_subscriptions"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:padding="32dp"
|
||||
android:text="@string/title_no_subscriptions"
|
||||
android:visibility="gone" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
</FrameLayout>
|
|
@ -6,6 +6,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
@ -218,23 +219,9 @@ public class WidgetConfig extends NbActivity {
|
|||
} else if (feedOrderFilter == FeedOrderFilter.OPENS && listOrderFilter == ListOrderFilter.DESCENDING) {
|
||||
return Integer.compare(o2.feedOpens, o1.feedOpens);
|
||||
} else if (feedOrderFilter == FeedOrderFilter.RECENT_STORY && listOrderFilter == ListOrderFilter.ASCENDING) {
|
||||
try {
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
Date firstDate = dateFormat.parse(o1.lastStoryDate);
|
||||
Date secondDate = dateFormat.parse(o2.lastStoryDate);
|
||||
return secondDate.compareTo(firstDate);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return compareLastStoryDateTimes(o1.lastStoryDate, o2.lastStoryDate, listOrderFilter);
|
||||
} else if (feedOrderFilter == FeedOrderFilter.RECENT_STORY && listOrderFilter == ListOrderFilter.DESCENDING) {
|
||||
try {
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
Date firstDate = dateFormat.parse(o1.lastStoryDate);
|
||||
Date secondDate = dateFormat.parse(o2.lastStoryDate);
|
||||
return firstDate.compareTo(secondDate);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return compareLastStoryDateTimes(o1.lastStoryDate, o2.lastStoryDate, listOrderFilter);
|
||||
} else if (feedOrderFilter == FeedOrderFilter.STORIES_MONTH && listOrderFilter == ListOrderFilter.ASCENDING) {
|
||||
return Integer.compare(o1.storiesPerMonth, o2.storiesPerMonth);
|
||||
} else if (feedOrderFilter == FeedOrderFilter.STORIES_MONTH && listOrderFilter == ListOrderFilter.DESCENDING) {
|
||||
|
@ -244,4 +231,28 @@ public class WidgetConfig extends NbActivity {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
private int compareLastStoryDateTimes(String firstDateTime, String secondDateTime, ListOrderFilter listOrderFilter) {
|
||||
try {
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
// found null last story date times on feeds
|
||||
if (TextUtils.isEmpty(firstDateTime)) {
|
||||
firstDateTime = "2000-01-01 00:00:00";
|
||||
}
|
||||
if (TextUtils.isEmpty(secondDateTime)) {
|
||||
secondDateTime = "2000-01-01 00:00:00";
|
||||
}
|
||||
|
||||
Date firstDate = dateFormat.parse(firstDateTime);
|
||||
Date secondDate = dateFormat.parse(secondDateTime);
|
||||
if (listOrderFilter == ListOrderFilter.ASCENDING) {
|
||||
return firstDate.compareTo(secondDate);
|
||||
} else {
|
||||
return secondDate.compareTo(firstDate);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -63,7 +63,7 @@ public class WidgetConfigAdapter extends RecyclerView.Adapter<WidgetConfigAdapte
|
|||
Date dateTime = dateFormat.parse(feed.lastStoryDate);
|
||||
CharSequence relativeTimeString = DateUtils.getRelativeTimeSpanString(dateTime.getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
|
||||
holder.textDetails.setText(relativeTimeString);
|
||||
} catch (ParseException e) {
|
||||
} catch (Exception e) {
|
||||
holder.textDetails.setText(feed.lastStoryDate);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue