mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-01 09:16:47 +01:00
fixed trends displaying
This commit is contained in:
parent
ab5562d985
commit
682d52adbe
@ -30,7 +30,7 @@ import android.widget.AdapterView
|
|||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
import com.squareup.otto.Subscribe
|
import com.squareup.otto.Subscribe
|
||||||
import kotlinx.android.synthetic.main.fragment_content_listview.*
|
import kotlinx.android.synthetic.main.fragment_content_listview.*
|
||||||
import org.mariotaku.sqliteqb.library.*
|
import org.mariotaku.sqliteqb.library.Expression
|
||||||
import org.mariotaku.twidere.R
|
import org.mariotaku.twidere.R
|
||||||
import org.mariotaku.twidere.adapter.TrendsAdapter
|
import org.mariotaku.twidere.adapter.TrendsAdapter
|
||||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_EXTRAS
|
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_EXTRAS
|
||||||
@ -38,7 +38,6 @@ import org.mariotaku.twidere.model.UserKey
|
|||||||
import org.mariotaku.twidere.model.message.TrendsRefreshedEvent
|
import org.mariotaku.twidere.model.message.TrendsRefreshedEvent
|
||||||
import org.mariotaku.twidere.model.tab.extra.TrendsTabExtras
|
import org.mariotaku.twidere.model.tab.extra.TrendsTabExtras
|
||||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedTrends
|
import org.mariotaku.twidere.provider.TwidereDataStore.CachedTrends
|
||||||
import org.mariotaku.twidere.util.DataStoreUtils.getTableNameByUri
|
|
||||||
import org.mariotaku.twidere.util.IntentUtils.openTweetSearch
|
import org.mariotaku.twidere.util.IntentUtils.openTweetSearch
|
||||||
import org.mariotaku.twidere.util.Utils
|
import org.mariotaku.twidere.util.Utils
|
||||||
|
|
||||||
@ -66,17 +65,10 @@ class TrendsSuggestionsFragment : AbsContentListViewFragment<TrendsAdapter>(), L
|
|||||||
|
|
||||||
override fun onCreateLoader(id: Int, args: Bundle?): Loader<Cursor> {
|
override fun onCreateLoader(id: Int, args: Bundle?): Loader<Cursor> {
|
||||||
val uri = CachedTrends.Local.CONTENT_URI
|
val uri = CachedTrends.Local.CONTENT_URI
|
||||||
val table = getTableNameByUri(uri)!!
|
val loaderWhere = Expression.and(Expression.equalsArgs(CachedTrends.ACCOUNT_KEY),
|
||||||
val timestampQuery = SQLQueryBuilder.select(Columns.Column(CachedTrends.TIMESTAMP))
|
Expression.equalsArgs(CachedTrends.WOEID)).sql
|
||||||
.from(Table(table))
|
val loaderWhereArgs = arrayOf(accountKey?.toString() ?: "", woeId.toString())
|
||||||
.orderBy(OrderBy(CachedTrends.TIMESTAMP, false))
|
return CursorLoader(activity, uri, CachedTrends.COLUMNS, loaderWhere, loaderWhereArgs, CachedTrends.TREND_ORDER)
|
||||||
.limit(1)
|
|
||||||
.build()
|
|
||||||
val where = Expression.and(Expression.equalsArgs(CachedTrends.ACCOUNT_KEY),
|
|
||||||
Expression.equalsArgs(CachedTrends.WOEID),
|
|
||||||
Expression.equals(Columns.Column(CachedTrends.TIMESTAMP), timestampQuery)).sql
|
|
||||||
val whereArgs = arrayOf(accountKey?.toString() ?: "", woeId.toString())
|
|
||||||
return CursorLoader(activity, uri, CachedTrends.COLUMNS, where, whereArgs, CachedTrends.TREND_ORDER)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(view: AdapterView<*>, child: View, position: Int, id: Long) {
|
override fun onItemClick(view: AdapterView<*>, child: View, position: Int, id: Long) {
|
||||||
|
@ -49,9 +49,9 @@ class GetTrendsTask(
|
|||||||
val twitter = details.newMicroBlogInstance(context, cls = MicroBlog::class.java)
|
val twitter = details.newMicroBlogInstance(context, cls = MicroBlog::class.java)
|
||||||
try {
|
try {
|
||||||
val trends = when {
|
val trends = when {
|
||||||
details.type == AccountType.FANFOU -> listOf(twitter.fanfouTrends)
|
details.type == AccountType.FANFOU -> twitter.fanfouTrends
|
||||||
else -> twitter.getLocationTrends(woeId)
|
else -> twitter.getLocationTrends(woeId).firstOrNull()
|
||||||
}
|
} ?: return
|
||||||
storeTrends(context.contentResolver, CachedTrends.Local.CONTENT_URI, trends)
|
storeTrends(context.contentResolver, CachedTrends.Local.CONTENT_URI, trends)
|
||||||
} catch (e: MicroBlogException) {
|
} catch (e: MicroBlogException) {
|
||||||
DebugLog.w(LOGTAG, tr = e)
|
DebugLog.w(LOGTAG, tr = e)
|
||||||
@ -62,7 +62,7 @@ class GetTrendsTask(
|
|||||||
bus.post(TrendsRefreshedEvent())
|
bus.post(TrendsRefreshedEvent())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeTrends(cr: ContentResolver, uri: Uri, trendsList: List<Trends>) {
|
private fun storeTrends(cr: ContentResolver, uri: Uri, trends: Trends) {
|
||||||
val hashtags = ArraySet<String>()
|
val hashtags = ArraySet<String>()
|
||||||
val deleteWhere = Expression.and(Expression.equalsArgs(CachedTrends.ACCOUNT_KEY),
|
val deleteWhere = Expression.and(Expression.equalsArgs(CachedTrends.ACCOUNT_KEY),
|
||||||
Expression.equalsArgs(CachedTrends.WOEID)).sql
|
Expression.equalsArgs(CachedTrends.WOEID)).sql
|
||||||
@ -71,7 +71,6 @@ class GetTrendsTask(
|
|||||||
|
|
||||||
val allTrends = ArrayList<ParcelableTrend>()
|
val allTrends = ArrayList<ParcelableTrend>()
|
||||||
|
|
||||||
trendsList.forEach { trends ->
|
|
||||||
trends.trends.forEachIndexed { idx, trend ->
|
trends.trends.forEachIndexed { idx, trend ->
|
||||||
val hashtag = trend.name.replaceFirst("#", "")
|
val hashtag = trend.name.replaceFirst("#", "")
|
||||||
hashtags.add(hashtag)
|
hashtags.add(hashtag)
|
||||||
@ -83,7 +82,6 @@ class GetTrendsTask(
|
|||||||
this.trend_order = idx
|
this.trend_order = idx
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ContentResolverUtils.bulkInsert(cr, uri, allTrends.map(ParcelableTrendValuesCreator::create))
|
ContentResolverUtils.bulkInsert(cr, uri, allTrends.map(ParcelableTrendValuesCreator::create))
|
||||||
ContentResolverUtils.bulkDelete(cr, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, false,
|
ContentResolverUtils.bulkDelete(cr, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, false,
|
||||||
hashtags, null)
|
hashtags, null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user