rewrote trends fragment
This commit is contained in:
parent
5b6db13f7a
commit
9e30071cc4
|
@ -40,6 +40,10 @@ public class ParcelableTrend implements Parcelable {
|
|||
@JsonField(name = "timestamp")
|
||||
@CursorField(CachedTrends.TIMESTAMP)
|
||||
public long timestamp;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "trend_order")
|
||||
@CursorField(CachedTrends.TREND_ORDER)
|
||||
public int trend_order;
|
||||
@JsonField(name = "name")
|
||||
@CursorField(value = CachedTrends.NAME)
|
||||
public String name;
|
||||
|
@ -51,6 +55,7 @@ public class ParcelableTrend implements Parcelable {
|
|||
", account_key=" + account_key +
|
||||
", woe_id=" + woe_id +
|
||||
", timestamp=" + timestamp +
|
||||
", trend_order=" + trend_order +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ public abstract class TabExtras implements Parcelable {
|
|||
case CustomTabType.HOME_TIMELINE: {
|
||||
return LoganSquare.parse(json, HomeTabExtras.class);
|
||||
}
|
||||
case CustomTabType.TRENDS_SUGGESTIONS: {
|
||||
return LoganSquare.parse(json, TrendsTabExtras.class);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.mariotaku.twidere.model.FiltersSubscriptionTableInfo;
|
|||
import org.mariotaku.twidere.model.ParcelableActivityTableInfo;
|
||||
import org.mariotaku.twidere.model.ParcelableDirectMessageTableInfo;
|
||||
import org.mariotaku.twidere.model.ParcelableStatusTableInfo;
|
||||
import org.mariotaku.twidere.model.ParcelableTrendTableInfo;
|
||||
import org.mariotaku.twidere.model.ParcelableUserTableInfo;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -190,9 +191,10 @@ public interface TwidereDataStore {
|
|||
|
||||
String TIMESTAMP = "timestamp";
|
||||
String WOEID = "woeid";
|
||||
String TREND_ORDER = "trend_order";
|
||||
|
||||
String[] COLUMNS = {_ID, ACCOUNT_KEY, WOEID, NAME, TIMESTAMP};
|
||||
String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT, TYPE_INT, TYPE_TEXT, TYPE_INT};
|
||||
String[] COLUMNS = ParcelableTrendTableInfo.COLUMNS;
|
||||
String[] TYPES = ParcelableTrendTableInfo.TYPES;
|
||||
|
||||
interface Local extends CachedTrends {
|
||||
String TABLE_NAME = "local_trends";
|
||||
|
|
|
@ -34,7 +34,7 @@ import static org.mariotaku.twidere.annotation.PreferenceType.STRING;
|
|||
public interface Constants extends TwidereConstants {
|
||||
|
||||
String DATABASES_NAME = "twidere.sqlite";
|
||||
int DATABASES_VERSION = 163;
|
||||
int DATABASES_VERSION = 164;
|
||||
|
||||
int EXTRA_FEATURES_NOTICE_VERSION = 0;
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.mariotaku.twidere.model.tab.conf.TrendsLocationExtraConfiguration;
|
|||
import org.mariotaku.twidere.model.tab.extra.TrendsTabExtras;
|
||||
|
||||
import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_PLACE;
|
||||
import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_WOEID;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/11/27.
|
||||
|
@ -44,7 +43,7 @@ public class TrendsTabConfiguration extends TabConfiguration {
|
|||
@Override
|
||||
public ExtraConfiguration[] getExtraConfigurations(Context context) {
|
||||
return new ExtraConfiguration[]{
|
||||
new TrendsLocationExtraConfiguration(EXTRA_WOEID).title(R.string.trends_location).mutable(true),
|
||||
new TrendsLocationExtraConfiguration(EXTRA_PLACE).title(R.string.trends_location).mutable(true),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -60,8 +59,7 @@ public class TrendsTabConfiguration extends TabConfiguration {
|
|||
extras.setWoeId(place.getWoeId());
|
||||
extras.setPlaceName(place.getName());
|
||||
} else {
|
||||
extras.setWoeId(0);
|
||||
extras.setPlaceName(null);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -31,10 +31,12 @@ import android.widget.ListView
|
|||
import com.squareup.otto.Subscribe
|
||||
import kotlinx.android.synthetic.main.fragment_content_listview.*
|
||||
import org.mariotaku.sqliteqb.library.*
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.TrendsAdapter
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_WOEID
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_EXTRAS
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.message.TrendsRefreshedEvent
|
||||
import org.mariotaku.twidere.model.tab.extra.TrendsTabExtras
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedTrends
|
||||
import org.mariotaku.twidere.util.DataStoreUtils.getTableNameByUri
|
||||
import org.mariotaku.twidere.util.IntentUtils.openTweetSearch
|
||||
|
@ -44,7 +46,12 @@ class TrendsSuggestionsFragment : AbsContentListViewFragment<TrendsAdapter>(), L
|
|||
|
||||
private val accountKey: UserKey? get() = Utils.getAccountKeys(context, arguments)?.firstOrNull()
|
||||
?: Utils.getDefaultAccountKey(context)
|
||||
private val woeId: Int get() = arguments.getInt(EXTRA_WOEID, 1)
|
||||
private val tabExtras: TrendsTabExtras? get() = arguments.getParcelable(EXTRA_EXTRAS)
|
||||
|
||||
private val woeId: Int get() {
|
||||
val id = tabExtras?.woeId ?: return 1
|
||||
return if (id > 0) id else 1
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
@ -69,7 +76,7 @@ class TrendsSuggestionsFragment : AbsContentListViewFragment<TrendsAdapter>(), L
|
|||
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.NAME)
|
||||
return CursorLoader(activity, uri, CachedTrends.COLUMNS, where, whereArgs, CachedTrends.TREND_ORDER)
|
||||
}
|
||||
|
||||
override fun onItemClick(view: AdapterView<*>, child: View, position: Int, id: Long) {
|
||||
|
@ -91,7 +98,11 @@ class TrendsSuggestionsFragment : AbsContentListViewFragment<TrendsAdapter>(), L
|
|||
|
||||
override fun onLoadFinished(loader: Loader<Cursor>, cursor: Cursor) {
|
||||
adapter.swapCursor(cursor)
|
||||
showContent()
|
||||
if (adapter.isEmpty) {
|
||||
showEmpty(R.drawable.ic_info_refresh, getString(R.string.swipe_down_to_refresh))
|
||||
} else {
|
||||
showContent()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRefresh() {
|
||||
|
|
|
@ -4,16 +4,18 @@ import android.content.ContentResolver
|
|||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.support.v4.util.ArraySet
|
||||
import com.squareup.otto.Bus
|
||||
import org.mariotaku.abstask.library.AbstractTask
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.Trends
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.model.ParcelableTrend
|
||||
import org.mariotaku.twidere.model.ParcelableTrendValuesCreator
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.message.TrendsRefreshedEvent
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedHashtags
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedTrends
|
||||
import org.mariotaku.twidere.util.ContentValuesCreator
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
||||
import org.mariotaku.twidere.util.content.ContentResolverUtils
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
|
@ -53,31 +55,34 @@ class GetTrendsTask(
|
|||
}
|
||||
|
||||
private fun storeTrends(cr: ContentResolver, uri: Uri, trendsList: List<Trends>) {
|
||||
val hashtags = ArrayList<String>()
|
||||
val hashtagValues = ArrayList<ContentValues>()
|
||||
val hashtags = ArraySet<String>()
|
||||
val deleteWhere = Expression.and(Expression.equalsArgs(CachedTrends.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(CachedTrends.WOEID)).sql
|
||||
val deleteWhereArgs = arrayOf(accountKey.toString(), woeId.toString())
|
||||
cr.delete(CachedTrends.Local.CONTENT_URI, deleteWhere, deleteWhereArgs)
|
||||
trendsList.forEach {
|
||||
|
||||
}
|
||||
if (trendsList.isNotEmpty()) {
|
||||
val valuesArray = ContentValuesCreator.createTrends(trendsList)
|
||||
for (values in valuesArray) {
|
||||
val hashtag = values.getAsString(CachedTrends.NAME).replaceFirst("#", "")
|
||||
if (hashtags.contains(hashtag)) {
|
||||
continue
|
||||
}
|
||||
val allTrends = ArrayList<ParcelableTrend>()
|
||||
|
||||
trendsList.forEach { trends ->
|
||||
trends.trends.forEachIndexed { idx, trend ->
|
||||
val hashtag = trend.name.replaceFirst("#", "")
|
||||
hashtags.add(hashtag)
|
||||
val hashtagValue = ContentValues()
|
||||
hashtagValue.put(CachedHashtags.NAME, hashtag)
|
||||
hashtagValues.add(hashtagValue)
|
||||
allTrends.add(ParcelableTrend().apply {
|
||||
this.account_key = accountKey
|
||||
this.woe_id = woeId
|
||||
this.name = trend.name
|
||||
this.timestamp = System.currentTimeMillis()
|
||||
this.trend_order = idx
|
||||
})
|
||||
}
|
||||
cr.delete(uri, null, null)
|
||||
ContentResolverUtils.bulkInsert(cr, uri, valuesArray)
|
||||
ContentResolverUtils.bulkDelete(cr, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, false, hashtags, null)
|
||||
ContentResolverUtils.bulkInsert(cr, CachedHashtags.CONTENT_URI, hashtagValues.toTypedArray())
|
||||
}
|
||||
ContentResolverUtils.bulkInsert(cr, uri, allTrends.map(ParcelableTrendValuesCreator::create))
|
||||
ContentResolverUtils.bulkDelete(cr, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, false,
|
||||
hashtags, null)
|
||||
ContentResolverUtils.bulkInsert(cr, CachedHashtags.CONTENT_URI, hashtags.map {
|
||||
val values = ContentValues()
|
||||
values.put(CachedHashtags.NAME, it)
|
||||
return@map values
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue