optimized TweetAdapter insertion, updated drawables

This commit is contained in:
nuclearfog 2020-06-29 10:31:11 +02:00
parent 83f454e66a
commit f17a6ca256
No known key found for this signature in database
GPG Key ID: ED35E22099354A64
5 changed files with 79 additions and 79 deletions

View File

@ -21,7 +21,7 @@
<entry key="assetSourceType" value="FILE" />
<entry key="autoMirrored" value="true" />
<entry key="outputName" value="no_banner" />
<entry key="sourceFile" value="$USER_HOME$/Schreibtisch/no_banner.svg" />
<entry key="sourceFile" value="$USER_HOME$/Dokumente/Unbenannt 2.svg" />
</map>
</option>
</PersistentState>

View File

@ -57,52 +57,53 @@ public class TweetAdapter extends Adapter<ViewHolder> {
this.settings = settings;
}
/**
* Insert data at specific index of the list
*
* @param data Tweet data
* @param index position to insert
*/
@MainThread
public void insert(@NonNull List<Tweet> data, int index) {
if (!tweets.isEmpty() && index >= 0 && index < tweets.size()) {
public void insertAt(@NonNull List<Tweet> data, int index) {
if (!tweets.isEmpty()) {
if (data.size() > MIN_COUNT) {
if (tweets.get(index) != null) {
// Add placeholder
tweets.add(index, null);
tweets.addAll(index, data);
notifyItemRangeInserted(index, data.size() + 1);
} else {
tweets.addAll(index, data);
notifyItemRangeInserted(index, data.size());
notifyItemInserted(index);
}
} else {
if (tweets.get(index) == null) {
// remove placeholder
tweets.remove(index);
if (data.isEmpty()) {
notifyItemRemoved(index);
} else if (data.size() == 1) {
tweets.add(index, data.get(0));
notifyItemChanged(index);
} else {
tweets.addAll(index, data);
notifyItemRangeInserted(index, data.size() - 1);
}
} else {
tweets.addAll(index, data);
notifyItemRangeInserted(index, data.size());
notifyItemRemoved(index);
}
}
} else {
tweets.addAll(data);
if (data.size() > MIN_COUNT) {
tweets.add(null);
}
notifyDataSetChanged();
tweets.addAll(index, data);
notifyItemRangeInserted(index, data.size());
}
}
/**
* Replace all items in the list
*
* @param data tweet data
*/
@MainThread
public void clear() {
tweets.clear();
public void replaceAll(@NonNull List<Tweet> data) {
tweets.addAll(data);
if (data.size() > MIN_COUNT) {
tweets.add(null);
}
notifyDataSetChanged();
}
/**
* t
* Remove specific tweet from list
*
* @param id ID of the tweet
*/
@MainThread
public void remove(long id) {
int index = -1;
@ -119,7 +120,11 @@ public class TweetAdapter extends Adapter<ViewHolder> {
}
}
/**
* check if list is empty
*
* @return true if list is empty
*/
public boolean isEmpty() {
return tweets.isEmpty();
}
@ -259,7 +264,6 @@ public class TweetAdapter extends Adapter<ViewHolder> {
class PlaceHolder extends ViewHolder {
final Button loadBtn;
PlaceHolder(@NonNull View v) {
@ -280,6 +284,13 @@ public class TweetAdapter extends Adapter<ViewHolder> {
*/
void onTweetClick(Tweet tweet);
/**
* called on placeholder click
*
* @param sinceId the tweet ID of the tweet below the holder
* @param maxId the tweet ID of the tweet over the holder
* @param pos position of the holder
*/
void onHolderClick(long sinceId, long maxId, int pos);
}
}

View File

@ -161,9 +161,11 @@ public class TweetFragment extends Fragment implements OnRefreshListener, TweetC
* @param pos position where tweets should be added
*/
public void setData(List<Tweet> tweets, int pos) {
if (pos == CLEAR_LIST)
adapter.clear();
adapter.insert(tweets, pos);
if (pos == CLEAR_LIST) {
adapter.replaceAll(tweets);
} else {
adapter.insertAt(tweets, pos);
}
}
/**

View File

@ -7,14 +7,7 @@
<group>
<clip-path android:pathData="M0,0h12000v4000h-12000z" />
<path
android:fillColor="#FFFFFF"
android:fillType="evenOdd"
android:pathData="M11533,5698C11521,5710 11501,5710 11489,5698L11419,5618 11348,5698C11336,5710 11316,5710 11304,5698 11291,5685 11291,5665 11304,5653L11376,5570 11304,5486C11291,5474 11291,5454 11304,5441 11316,5429 11336,5429 11348,5441L11419,5521 11489,5441C11501,5429 11521,5429 11533,5441 11546,5454 11546,5474 11533,5486L11461,5570 11533,5653C11546,5665 11546,5685 11533,5698L11533,5698Z"
android:strokeColor="#00000000"
android:strokeLineJoin="round"
android:strokeWidth="28.222" />
<path
android:fillColor="#000000"
android:fillColor="#111111"
android:fillType="evenOdd"
android:pathData="M6000,4000L0,4000 0,0 12000,0 12000,4000 6000,4000Z"
android:strokeColor="#00000000"
@ -24,13 +17,13 @@
android:fillColor="#00000000"
android:fillType="evenOdd"
android:pathData="M6000,4000L0,4000 0,0 12000,0 12000,4000 6000,4000Z"
android:strokeColor="#3465A4"
android:strokeColor="#111111"
android:strokeLineJoin="round"
android:strokeWidth="28.222" />
<path
android:fillColor="#FFFFFF"
android:fillType="evenOdd"
android:pathData="M11262,1189C11236,1215 11194,1215 11168,1189L11023,1023 10877,1189C10851,1215 10809,1215 10783,1189 10758,1163 10758,1122 10783,1096L10935,923 10783,749C10758,723 10758,682 10783,656 10809,630 10851,630 10877,656L11023,823 11168,656C11194,630 11236,630 11262,656 11287,682 11287,723 11262,749L11110,923 11262,1096C11287,1122 11287,1163 11262,1189L11262,1189Z"
android:pathData="M11714,687C11692,708 11657,708 11635,687L11512,551 11388,687C11366,708 11331,708 11309,687 11287,666 11287,632 11309,611L11438,470 11309,329C11287,308 11287,274 11309,253 11331,232 11366,232 11388,253L11512,389 11635,253C11657,232 11692,232 11714,253 11736,274 11736,308 11714,329L11585,470 11714,611C11736,632 11736,666 11714,687L11714,687Z"
android:strokeColor="#00000000"
android:strokeLineJoin="round"
android:strokeWidth="28.222" />

View File

@ -1,37 +1,31 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
<vector android:autoMirrored="true"
android:height="40dp"
android:viewportHeight="4000"
android:viewportWidth="4000"
android:viewportHeight="4000">
<group>
<clip-path android:pathData="M0,0h4000v4000h-4000z" />
<path
android:pathData="M11533,5698C11521,5710 11501,5710 11489,5698L11419,5618 11348,5698C11336,5710 11316,5710 11304,5698 11291,5685 11291,5665 11304,5653L11376,5570 11304,5486C11291,5474 11291,5454 11304,5441 11316,5429 11336,5429 11348,5441L11419,5521 11489,5441C11501,5429 11521,5429 11533,5441 11546,5454 11546,5474 11533,5486L11461,5570 11533,5653C11546,5665 11546,5685 11533,5698L11533,5698Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="#FFFFFF"
android:strokeColor="#00000000"
android:fillType="evenOdd" />
<path
android:pathData="M2000,4000L0,4000 0,0 4000,0 4000,4000 2000,4000Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="#000000"
android:strokeColor="#00000000"
android:fillType="evenOdd" />
<path
android:pathData="M2000,4000L0,4000 0,0 4000,0 4000,4000 2000,4000Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="#00000000"
android:strokeColor="#3465A4"
android:fillType="evenOdd" />
<path
android:pathData="M3417,1089C3391,1115 3349,1115 3323,1089L3178,923 3032,1089C3006,1115 2964,1115 2938,1089 2913,1063 2913,1022 2938,996L3090,823 2938,649C2913,623 2913,582 2938,556 2964,530 3006,530 3032,556L3178,723 3323,556C3349,530 3391,530 3417,556 3442,582 3442,623 3417,649L3265,823 3417,996C3442,1022 3442,1063 3417,1089L3417,1089Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="#FFFFFF"
android:strokeColor="#00000000"
android:fillType="evenOdd" />
</group>
android:width="40dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<group>
<clip-path android:pathData="M0,0h4000v4000h-4000z" />
<path
android:fillColor="#111111"
android:fillType="evenOdd"
android:pathData="M2000,4000L0,4000 0,0 4000,0 4000,4000 2000,4000Z"
android:strokeColor="#00000000"
android:strokeLineJoin="round"
android:strokeWidth="28.222" />
<path
android:fillColor="#00000000"
android:fillType="evenOdd"
android:pathData="M2000,4000L0,4000 0,0 4000,0 4000,4000 2000,4000Z"
android:strokeColor="#111111"
android:strokeLineJoin="round"
android:strokeWidth="28.222" />
<path
android:fillColor="#FFFFFF"
android:fillType="evenOdd"
android:pathData="M3691,687C3669,708 3634,708 3612,687L3489,551 3365,687C3343,708 3308,708 3286,687 3264,666 3264,632 3286,611L3415,470 3286,329C3264,308 3264,274 3286,253 3308,232 3343,232 3365,253L3489,389 3612,253C3634,232 3669,232 3691,253 3713,274 3713,308 3691,329L3562,470 3691,611C3713,632 3713,666 3691,687L3691,687Z"
android:strokeColor="#00000000"
android:strokeLineJoin="round"
android:strokeWidth="28.222" />
</group>
</vector>