bug fix, code cleanup

This commit is contained in:
nuclearfog 2023-11-17 21:11:12 +01:00
parent 79995d78a4
commit c98ebd9e4b
No known key found for this signature in database
GPG Key ID: 03488A185C476379
17 changed files with 80 additions and 161 deletions

View File

@ -377,9 +377,6 @@ public class MastodonStatus implements Status {
if (embeddedStatus instanceof MastodonStatus) {
((MastodonStatus) embeddedStatus).setRepost(reposted);
}
if (!reposted && reblogCount > 0) {
reblogCount--;
}
}
/**
@ -390,9 +387,6 @@ public class MastodonStatus implements Status {
if (embeddedStatus instanceof MastodonStatus) {
((MastodonStatus) embeddedStatus).setFavorite(favorited);
}
if (!favorited && favoriteCount > 0) {
favoriteCount--;
}
}
/**

View File

@ -369,7 +369,7 @@ public class AppDatabase {
// delete old favorits
String[] delArgs = {Long.toString(ownerId)};
db.delete(FavoriteTable.TABLE, FAVORITE_SELECT_OWNER, delArgs);
// add new favorits
if (!statuses.isEmpty()) {
for (Status status : statuses) {
saveStatus(status, db, 0);
@ -389,10 +389,10 @@ public class AppDatabase {
public void saveBookmarkTimeline(Statuses statuses, long ownerId) {
synchronized (adapter) {
SQLiteDatabase db = adapter.getDbWrite();
// delete old favorits
// delete old bookmarks
String[] delArgs = {Long.toString(ownerId)};
db.delete(BookmarkTable.TABLE, BOOKMARK_SELECT_OWNER, delArgs);
// add new bookmarks
if (!statuses.isEmpty()) {
for (Status status : statuses) {
saveStatus(status, db, 0);
@ -1206,7 +1206,7 @@ public class AppDatabase {
@Nullable
private Media getMedia(SQLiteDatabase db, String key) {
String[] args = {key};
Cursor c = db.query(MediaTable.TABLE, DatabaseMedia.PROJECTION, MEDIA_SELECT, args, null, null, null, SINGLE_ITEM);
Cursor c = db.query(MediaTable.TABLE, DatabaseMedia.COLUMNS, MEDIA_SELECT, args, null, null, null, SINGLE_ITEM);
Media result = null;
if (c.moveToFirst())
result = new DatabaseMedia(c);

View File

@ -89,20 +89,20 @@ public class DatabaseAdapter {
+ TagTable.LOCATION + " INTEGER,"
+ TagTable.INDEX + " INTEGER,"
+ TagTable.VOL + " INTEGER,"
+ TagTable.TAG_NAME + " TEXT);";
+ TagTable.TAG_NAME + " TEXT NOT NULL);";
/**
* SQL query to create a table for user logins
*/
private static final String TABLE_ACCOUNTS = "CREATE TABLE IF NOT EXISTS "
+ AccountTable.TABLE + "("
+ AccountTable.ID + " INTEGER,"
+ AccountTable.ID + " INTEGER NOT NULL,"
+ AccountTable.DATE + " INTEGER,"
+ AccountTable.USERNAME + " TEXT,"
+ AccountTable.IMAGE + " TEXT,"
+ AccountTable.ACCESS_TOKEN + " TEXT,"
+ AccountTable.TOKEN_SECRET + " TEXT,"
+ AccountTable.HOSTNAME + " TEXT,"
+ AccountTable.HOSTNAME + " TEXT NOT NULL,"
+ AccountTable.API + " INTEGER,"
+ AccountTable.CLIENT_ID + " TEXT,"
+ AccountTable.CLIENT_SECRET + " TEXT,"

View File

@ -26,14 +26,14 @@ public class DatabaseAccount implements Account, AccountTable {
private long userId;
private long loginDate;
private int apiType;
private String accessToken = "";
private String tokenSecret = "";
private String consumerToken = "";
private String consumerSecret = "";
private String bearerToken = "";
private String host = "";
private String screenName = "";
private String profileImage = "";
private String accessToken;
private String tokenSecret;
private String consumerToken;
private String consumerSecret;
private String bearerToken;
private String hostname;
private String screenName;
private String profileImage;
/**
* @param cursor database cursor using this {@link #COLUMNS}
@ -42,31 +42,14 @@ public class DatabaseAccount implements Account, AccountTable {
userId = cursor.getLong(0);
apiType = cursor.getInt(1);
loginDate = cursor.getLong(2);
String accessToken = cursor.getString(3);
String tokenSecret = cursor.getString(4);
String consumerToken = cursor.getString(5);
String consumerSecret = cursor.getString(6);
String bearerToken = cursor.getString(7);
String host = cursor.getString(8);
String name = cursor.getString(9);
String image = cursor.getString(10);
if (accessToken != null)
this.accessToken = accessToken;
if (tokenSecret != null)
this.tokenSecret = tokenSecret;
if (consumerToken != null)
this.consumerToken = consumerToken;
if (consumerSecret != null)
this.consumerSecret = consumerSecret;
if (bearerToken != null)
this.bearerToken = bearerToken;
if (host != null)
this.host = host;
if (image != null)
this.profileImage = image;
if (name != null)
this.screenName = name;
accessToken = cursor.getString(3);
tokenSecret = cursor.getString(4);
consumerToken = cursor.getString(5);
consumerSecret = cursor.getString(6);
bearerToken = cursor.getString(7);
hostname = cursor.getString(8);
screenName = cursor.getString(9);
profileImage = cursor.getString(10);
}
@ -126,7 +109,7 @@ public class DatabaseAccount implements Account, AccountTable {
@Override
public String getHostname() {
return host;
return hostname;
}

View File

@ -22,23 +22,17 @@ public class DatabaseEmoji implements Emoji, EmojiTable {
*/
public static final String[] PROJECTION = {CODE, URL, CATEGORY};
private String code = "";
private String url = "";
private String category = "";
private String code;
private String url;
private String category;
/**
* @param cursor database cursor
*/
public DatabaseEmoji(Cursor cursor) {
String code = cursor.getString(0);
String url = cursor.getString(1);
String category = cursor.getString(2);
if (code != null)
this.code = code;
if (url != null)
this.url = url;
if (category != null)
this.category = category;
code = cursor.getString(0);
url = cursor.getString(1);
category = cursor.getString(2);
}

View File

@ -23,26 +23,18 @@ public class DatabaseLocation implements Location, LocationTable {
public static final String[] PROJECTION = {ID, PLACE, COUNTRY, FULLNAME, COORDINATES};
private long id;
private String name = "";
private String coordinates = "";
private String country = "";
private String place = "";
private String name;
private String coordinates;
private String country;
private String place;
public DatabaseLocation(Cursor cursor) {
id = cursor.getLong(0);
String place = cursor.getString(1);
String country = cursor.getString(2);
String name = cursor.getString(3);
String coordinates = cursor.getString(4);
if (name != null)
this.name = name;
if (coordinates != null)
this.coordinates = coordinates;
if (country != null)
this.country = country;
if (place != null)
this.place = place;
place = cursor.getString(1);
country = cursor.getString(2);
name = cursor.getString(3);
coordinates = cursor.getString(4);
}

View File

@ -20,36 +20,25 @@ public class DatabaseMedia implements Media, MediaTable {
/**
*
*/
public static final String[] PROJECTION = {KEY, URL, PREVIEW, TYPE, DESCRIPTION, BLUR};
public static final String[] COLUMNS = {KEY, URL, PREVIEW, TYPE, DESCRIPTION, BLUR};
private int mediaType;
private String key = "";
private String url = "";
private String preview = "";
private String description = "";
private String blurHash = "";
private String key;
private String url;
private String preview;
private String description;
private String blurHash;
/**
* @param cursor database cursor containing media table
* @param cursor database cursor containing this {@link #COLUMNS}
*/
public DatabaseMedia(Cursor cursor) {
String key = cursor.getString(0);
String url = cursor.getString(1);
String preview = cursor.getString(2);
String description = cursor.getString(3);
String blurHash = cursor.getString(4);
key = cursor.getString(0);
url = cursor.getString(1);
preview = cursor.getString(2);
description = cursor.getString(3);
blurHash = cursor.getString(4);
mediaType = cursor.getInt(3);
if (key != null)
this.key = key;
if (url != null)
this.url = url;
if (preview != null)
this.preview = preview;
if (description != null)
this.description = description;
if (blurHash != null)
this.blurHash = blurHash;
}

View File

@ -41,12 +41,12 @@ public class DatabaseStatus implements Status, StatusTable, StatusPropertiesTabl
private Media[] medias = {};
private Emoji[] emojis = {};
private Card[] cards = {};
private String replyName = "";
private String text = "";
private String source = "";
private String userMentions = "";
private String statusUrl = "";
private String language = "";
private String replyName;
private String text;
private String source;
private String userMentions;
private String statusUrl;
private String language;
/**
* @param cursor database cursor
@ -66,14 +66,14 @@ public class DatabaseStatus implements Status, StatusTable, StatusPropertiesTabl
embeddedId = cursor.getLong(cursor.getColumnIndexOrThrow(EMBEDDED));
myRepostId = cursor.getLong(cursor.getColumnIndexOrThrow(REPOST_ID));
editedAt = cursor.getLong(cursor.getColumnIndexOrThrow(EDITED_AT));
String statusUrl = cursor.getString(cursor.getColumnIndexOrThrow(URL));
String language = cursor.getString(cursor.getColumnIndexOrThrow(LANGUAGE));
statusUrl = cursor.getString(cursor.getColumnIndexOrThrow(URL));
language = cursor.getString(cursor.getColumnIndexOrThrow(LANGUAGE));
source = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE));
text = cursor.getString(cursor.getColumnIndexOrThrow(TEXT));
replyName = cursor.getString(cursor.getColumnIndexOrThrow(REPLYNAME));
userMentions = cursor.getString(cursor.getColumnIndexOrThrow(MENTIONS));
String mediaKeys = cursor.getString(cursor.getColumnIndexOrThrow(MEDIA));
String emojiKeys = cursor.getString(cursor.getColumnIndexOrThrow(EMOJI));
String source = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE));
String text = cursor.getString(cursor.getColumnIndexOrThrow(TEXT));
String replyName = cursor.getString(cursor.getColumnIndexOrThrow(REPLYNAME));
String userMentions = cursor.getString(cursor.getColumnIndexOrThrow(MENTIONS));
int register = cursor.getInt(cursor.getColumnIndexOrThrow(REGISTER));
favorited = (register & MASK_STATUS_FAVORITED) != 0;
@ -91,22 +91,12 @@ public class DatabaseStatus implements Status, StatusTable, StatusPropertiesTabl
visibility = VISIBLE_UNLISTED;
else
visibility = VISIBLE_PUBLIC;
if (mediaKeys != null && !mediaKeys.isEmpty())
if (mediaKeys != null && !mediaKeys.isEmpty()) {
this.mediaKeys = KEY_SEPARATOR.split(mediaKeys);
if (emojiKeys != null && !emojiKeys.isEmpty())
}
if (emojiKeys != null && !emojiKeys.isEmpty()) {
this.emojiKeys = KEY_SEPARATOR.split(emojiKeys);
if (statusUrl != null)
this.statusUrl = statusUrl;
if (language != null)
this.language = language;
if (replyName != null)
this.replyName = replyName;
if (source != null)
this.source = source;
if (text != null)
this.text = text;
if (userMentions != null)
this.userMentions = userMentions;
}
}

View File

@ -22,7 +22,7 @@ public class DatabaseTag implements Tag, TagTable {
*/
public static final String[] COLUMNS = {TAG_NAME, VOL, INDEX, LOCATION, ID};
private String name = "";
private String name;
private int popularity;
private int rank;
private long id;
@ -32,14 +32,11 @@ public class DatabaseTag implements Tag, TagTable {
* @param cursor database cursor using this {@link #COLUMNS} projection
*/
public DatabaseTag(Cursor cursor) {
String name = cursor.getString(0);
name = cursor.getString(0);
popularity = cursor.getInt(1);
rank = cursor.getInt(2);
locationId = cursor.getLong(3);
id = cursor.getLong(4);
if (name != null) {
this.name = name;
}
}

View File

@ -444,7 +444,7 @@ public class MainActivity extends AppCompatActivity implements ActivityResultCal
@Override
public void onResult(CredentialsLoader.Result result) {
public void onResult(@NonNull CredentialsLoader.Result result) {
setCurrentUser(result.user);
}

View File

@ -23,8 +23,6 @@ import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.async.AsyncExecutor.AsyncCallback;
import org.nuclearfog.twidda.backend.async.TagAction;
import org.nuclearfog.twidda.backend.async.TagAction.Param;
import org.nuclearfog.twidda.backend.async.TagAction.Result;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.config.GlobalSettings;
@ -40,7 +38,7 @@ import java.io.Serializable;
*
* @author nuclearfog
*/
public class SearchActivity extends AppCompatActivity implements OnClickListener, OnTabSelectedListener, OnQueryTextListener, AsyncCallback<Result> {
public class SearchActivity extends AppCompatActivity implements OnClickListener, OnTabSelectedListener, OnQueryTextListener, AsyncCallback<TagAction.Result> {
/**
* Key for the search query, required
@ -97,7 +95,7 @@ public class SearchActivity extends AppCompatActivity implements OnClickListener
} else if (query != null) {
search = query;
if (search.matches("^#\\S+") && !search.matches("^#\\d+")) {
Param param = new Param(Param.LOAD, search);
TagAction.Param param = new TagAction.Param(TagAction.Param.LOAD, search);
tagAction.execute(param, this);
}
}
@ -205,11 +203,11 @@ public class SearchActivity extends AppCompatActivity implements OnClickListener
// follow/unfollow tag
else if (item.getItemId() == R.id.search_tag) {
if (tag != null && tagAction.isIdle()) {
Param param;
TagAction.Param param;
if (tag.following())
param = new Param(Param.UNFOLLOW, tag.getName());
param = new TagAction.Param(TagAction.Param.UNFOLLOW, tag.getName());
else
param = new Param(Param.FOLLOW, tag.getName());
param = new TagAction.Param(TagAction.Param.FOLLOW, tag.getName());
tagAction.execute(param, this);
}
}
@ -256,21 +254,21 @@ public class SearchActivity extends AppCompatActivity implements OnClickListener
@Override
public void onResult(@NonNull Result result) {
public void onResult(@NonNull TagAction.Result result) {
if (result.tag != null) {
this.tag = result.tag;
invalidateMenu();
}
switch (result.mode) {
case Result.FOLLOW:
case TagAction.Result.FOLLOW:
Toast.makeText(getApplicationContext(), R.string.info_tag_followed, Toast.LENGTH_SHORT).show();
break;
case Result.UNFOLLOW:
case TagAction.Result.UNFOLLOW:
Toast.makeText(getApplicationContext(), R.string.info_tag_unfollowed, Toast.LENGTH_SHORT).show();
break;
case Result.ERROR:
case TagAction.Result.ERROR:
if (result.exception == null || result.exception.getErrorCode() != ConnectionException.HTTP_FORBIDDEN)
ErrorUtils.showErrorMessage(this, result.exception);
break;

View File

@ -24,7 +24,6 @@ import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.StringUtils;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.model.Account;
import org.nuclearfog.twidda.model.User;
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation;

View File

@ -21,18 +21,6 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<TextView
android:id="@+id/item_account_username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:lines="1"
android:textSize="@dimen/login_name_textsize_big"
android:layout_marginStart="@dimen/login_layout_margin"
android:layout_marginEnd="@dimen/login_layout_margin"
app:layout_constraintStart_toEndOf="@id/item_account_profile"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@id/item_account_remove" />
<TextView
android:id="@+id/item_account_screenname"
android:layout_width="0dp"
@ -42,7 +30,7 @@
android:layout_marginStart="@dimen/login_layout_margin"
android:layout_marginEnd="@dimen/login_layout_margin"
app:layout_constraintStart_toEndOf="@id/item_account_profile"
app:layout_constraintTop_toBottomOf="@id/item_account_username"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/item_account_date"
app:layout_constraintEnd_toStartOf="@id/item_account_remove" />
@ -52,10 +40,10 @@
android:layout_height="wrap_content"
android:textSize="@dimen/login_date_textsize"
android:layout_marginStart="@dimen/login_layout_margin"
android:layout_marginTop="@dimen/login_layout_margin"
android:layout_marginEnd="@dimen/login_layout_margin"
app:layout_constraintStart_toEndOf="@id/item_account_profile"
app:layout_constraintTop_toBottomOf="@id/item_account_screenname"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/item_account_remove" />
<ImageButton

View File

@ -194,7 +194,6 @@
<string name="settings_follow_color">Follow Icon</string>
<string name="settings_enable_toolbar_overlap">Kompakte Profilansicht</string>
<string name="confirm_remove_filter">Filter löschen?</string>
<string name="account_user_unnamed">\'unbenannt\'</string>
<string name="menu_excluded_users">Blocklisten</string>
<string name="menu_hint_mute_user">\@name stummschalten</string>
<string name="menu_hint_block_user">\@name blockieren</string>

View File

@ -245,7 +245,6 @@
<string name="status_translate_source">Traducido por:\u0020</string>
<string name="status_translate_source_language">Idioma:\u0020</string>
<string name="confirm_remove_account">¿Eliminar cuenta de la lista?</string>
<string name="account_user_unnamed">\'sinnombre\'</string>
<string name="toolbar_status_favoriter">Usuario marcando como favorito este estado</string>
<string name="toolbar_status_liker">Usuario le está gustando este estado</string>
<string name="time_now">Ahora</string>

View File

@ -117,7 +117,6 @@
<dimen name="item_user_textsize_notification">12sp</dimen>
<!--dimens of item_account.xml-->
<dimen name="login_name_textsize_big">14sp</dimen>
<dimen name="login_name_textsize">12sp</dimen>
<dimen name="login_date_textsize">11sp</dimen>
<dimen name="login_card_padding">8dp</dimen>

View File

@ -13,7 +13,6 @@
<string name="login_sec_opt" translatable="false">2.</string>
<string name="login_trd_opt" translatable="false">3.</string>
<string name="login_4th_opt" translatable="false">4.</string>
<string name="account_user_id_prefix" translatable="false">User ID:</string>
<!-- toast messages to inform user -->
<string name="info_list_removed">Userlist removed</string>
@ -315,7 +314,6 @@
<string name="confirm_accept_follow_request">accept follow request?</string>
<string name="confirm_remove_account">remove account from list?</string>
<string name="confirm_remove_filter">delete filter?</string>
<string name="account_user_unnamed">\'unnamed\'</string>
<string name="toolbar_status_favoriter">User favoriting this status</string>
<string name="toolbar_status_liker">User liking this status</string>
<string name="time_now">now</string>