Some fixes

This commit is contained in:
Thomas 2023-01-17 16:41:39 +01:00
parent e0e2f7789b
commit 3b30708954
18 changed files with 193 additions and 78 deletions

View file

@ -113,7 +113,7 @@ public class AboutActivity extends BaseBarActivity {
if (relationShips != null && relationShips.size() > 0) {
if (!relationShips.get(0).following) {
binding.accountFollow.setVisibility(View.VISIBLE);
binding.accountFollow.setOnClickListener(v -> accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false)
binding.accountFollow.setOnClickListener(v -> accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false, null)
.observe(AboutActivity.this, relationShip -> binding.accountFollow.setVisibility(View.GONE)));
}
}

View file

@ -65,6 +65,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
@ -641,7 +642,20 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
}
}
if (statusReply.language != null && !statusReply.language.isEmpty()) {
statusDraftList.get(0).language = statusReply.language;
Set<String> storedLanguages = sharedpreferences.getStringSet(getString(R.string.SET_SELECTED_LANGUAGE), null);
if (storedLanguages == null || storedLanguages.size() == 0) {
statusDraftList.get(0).language = statusReply.language;
} else {
if (storedLanguages.contains(statusReply.language)) {
statusDraftList.get(0).language = statusReply.language;
} else {
String currentCode = sharedpreferences.getString(getString(R.string.SET_COMPOSE_LANGUAGE) + account.user_id + account.instance, Locale.getDefault().getLanguage());
if (currentCode.isEmpty()) {
currentCode = "EN";
}
statusDraftList.get(0).language = currentCode;
}
}
}
//StatusDraftList at this point should only have one element
statusList.addAll(statusDraftList);

View file

@ -93,7 +93,7 @@ public class PartnerShipActivity extends BaseBarActivity {
if (relationShips != null && relationShips.size() > 0) {
if (!relationShips.get(0).following) {
binding.accountFollow.setVisibility(View.VISIBLE);
binding.accountFollow.setOnClickListener(v -> accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false)
binding.accountFollow.setOnClickListener(v -> accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false, null)
.observe(PartnerShipActivity.this, relationShip -> binding.accountFollow.setVisibility(View.GONE)));
}
}

View file

@ -83,6 +83,7 @@ import app.fedilab.android.client.entities.api.Field;
import app.fedilab.android.client.entities.api.IdentityProof;
import app.fedilab.android.client.entities.api.MastodonList;
import app.fedilab.android.client.entities.api.RelationShip;
import app.fedilab.android.client.entities.app.Languages;
import app.fedilab.android.client.entities.app.Pinned;
import app.fedilab.android.client.entities.app.PinnedTimeline;
import app.fedilab.android.client.entities.app.RemoteInstance;
@ -467,7 +468,7 @@ public class ProfileActivity extends BaseActivity {
Toasty.info(ProfileActivity.this, getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show();
} else if (doAction == action.FOLLOW) {
binding.accountFollow.setEnabled(false);
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false)
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false, null)
.observe(ProfileActivity.this, relationShip -> {
this.relationship = relationShip;
updateAccount();
@ -660,7 +661,7 @@ public class ProfileActivity extends BaseActivity {
binding.accountNotification.setOnClickListener(v -> {
if (relationship != null && relationship.following) {
relationship.notifying = !relationship.notifying;
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, relationship.showing_reblogs, relationship.notifying)
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, relationship.showing_reblogs, relationship.notifying, relationship.languages)
.observe(ProfileActivity.this, relationShip -> {
this.relationship = relationShip;
updateAccount();
@ -726,6 +727,7 @@ public class ProfileActivity extends BaseActivity {
menu.findItem(R.id.action_direct_message).setVisible(false);
menu.findItem(R.id.action_add_to_list).setVisible(false);
menu.findItem(R.id.action_mute_home).setVisible(false);
menu.findItem(R.id.action_subscribed_language).setVisible(false);
} else {
menu.findItem(R.id.action_block).setVisible(true);
menu.findItem(R.id.action_mute).setVisible(true);
@ -739,6 +741,7 @@ public class ProfileActivity extends BaseActivity {
menu.findItem(R.id.action_hide_boost).setVisible(false);
menu.findItem(R.id.action_endorse).setVisible(false);
menu.findItem(R.id.action_mute_home).setVisible(false);
menu.findItem(R.id.action_subscribed_language).setVisible(false);
}
if (relationship.blocking) {
menu.findItem(R.id.action_block).setTitle(R.string.action_unblock);
@ -898,13 +901,70 @@ public class ProfileActivity extends BaseActivity {
.observe(ProfileActivity.this, relationShip -> this.relationship = relationShip);
}
return true;
} else if (itemId == R.id.action_subscribed_language) {
if (relationship != null) {
List<String> subscribedLanguages = relationship.languages;
Set<String> storedLanguages = sharedpreferences.getStringSet(getString(R.string.SET_SELECTED_LANGUAGE), null);
List<Languages.Language> languages = Languages.get(ProfileActivity.this);
if (languages == null) {
return true;
}
String[] codesArr;
String[] languagesArr;
boolean[] presentArr;
if (storedLanguages != null && storedLanguages.size() > 0) {
int i = 0;
codesArr = new String[storedLanguages.size()];
languagesArr = new String[storedLanguages.size()];
presentArr = new boolean[storedLanguages.size()];
for (String code : storedLanguages) {
for (Languages.Language language : languages) {
if (language.code.equalsIgnoreCase(code)) {
languagesArr[i] = language.language;
}
}
codesArr[i] = code;
presentArr[i] = subscribedLanguages != null && subscribedLanguages.contains(code);
i++;
}
} else {
codesArr = new String[languages.size()];
presentArr = new boolean[languages.size()];
languagesArr = new String[languages.size()];
int i = 0;
for (Languages.Language language : languages) {
codesArr[i] = language.code;
languagesArr[i] = language.language;
if (subscribedLanguages != null && subscribedLanguages.contains(language.code)) {
presentArr[i] = true;
}
i++;
}
}
AlertDialog.Builder builder = new MaterialAlertDialogBuilder(ProfileActivity.this, Helper.dialogStyle());
builder.setTitle(getString(R.string.filter_languages));
builder.setMultiChoiceItems(languagesArr, presentArr, (dialog, which, isChecked) -> {
List<String> languagesFilter = new ArrayList<>();
for (int i = 0; i < codesArr.length; i++) {
if (presentArr[i]) {
languagesFilter.add(codesArr[i]);
}
}
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, relationship.showing_reblogs, relationship.notifying, languagesFilter)
.observe(ProfileActivity.this, relationShip -> this.relationship = relationShip);
});
builder.setNegativeButton(R.string.close, (dialog, which) -> dialog.dismiss());
builder.create().show();
}
return true;
} else if (itemId == R.id.action_hide_boost) {
if (relationship != null)
if (relationship.showing_reblogs) {
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, false, relationship.notifying)
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, false, relationship.notifying, relationship.languages)
.observe(ProfileActivity.this, relationShip -> this.relationship = relationShip);
} else {
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, relationship.notifying)
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, relationship.notifying, relationship.languages)
.observe(ProfileActivity.this, relationShip -> this.relationship = relationShip);
}
return true;
@ -949,7 +1009,7 @@ public class ProfileActivity extends BaseActivity {
}
builderSingle.setMultiChoiceItems(listsArray, presentArray, (dialog, which, isChecked) -> {
if (relationship == null || !relationship.following) {
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false)
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false, null)
.observe(ProfileActivity.this, newRelationShip -> {
if (newRelationShip != null) {
relationship = newRelationShip;

View file

@ -174,7 +174,8 @@ public interface MastodonAccountsService {
@Header("Authorization") String app_token,
@Path("id") String id,
@Field("reblogs") boolean reblogs,
@Field("notify") boolean notify
@Field("notify") boolean notify,
@Field("languages[]") List<String> languages
);
//Follow account

View file

@ -16,6 +16,8 @@ package app.fedilab.android.client.entities.api;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class RelationShip {
@SerializedName("id")
@ -40,6 +42,8 @@ public class RelationShip {
public boolean requested;
@SerializedName("domain_blocking")
public boolean domain_blocking;
@SerializedName("languages")
public List<String> languages;
@SerializedName("endorsed")
public boolean endorsed;
@SerializedName("note")

View file

@ -203,7 +203,7 @@ public class CrossActionHelper {
break;
case FOLLOW_ACTION:
assert accountsVM != null;
accountsVM.follow(ownerAccount.instance, ownerAccount.token, targetedAccount.id, true, false)
accountsVM.follow(ownerAccount.instance, ownerAccount.token, targetedAccount.id, true, false, null)
.observe((LifecycleOwner) context, relationShip -> Toasty.info(context, context.getString(R.string.toast_follow), Toasty.LENGTH_SHORT).show());
break;
case UNFOLLOW_ACTION:

View file

@ -1861,7 +1861,7 @@ public class Helper {
if (!relationShips.get(0).following) {
binding.acccountContainer.setVisibility(View.VISIBLE);
binding.accountFollow.setVisibility(View.VISIBLE);
binding.accountFollow.setOnClickListener(v -> accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false)
binding.accountFollow.setOnClickListener(v -> accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false, null)
.observe((LifecycleOwner) activity, relationShip -> binding.accountFollow.setVisibility(View.GONE)));
}
}

View file

@ -229,7 +229,7 @@ public class AccountAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
Toasty.info(context, context.getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show();
} else if (finalDoAction == ProfileActivity.action.FOLLOW) {
accountViewHolder.binding.followAction.setEnabled(false);
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false)
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false, null)
.observe((LifecycleOwner) context, relationShip -> {
account.relationShip = relationShip;
adapter.notifyItemChanged(position);

View file

@ -49,7 +49,6 @@ import android.os.Looper;
import android.text.Html;
import android.text.SpannableString;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@ -693,7 +692,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.actionButtonMaths.setOnClickListener(v -> {
status.mathsShown = !status.mathsShown;
Log.v(Helper.TAG, "notifyItemChanged: " + holder.getBindingAdapterPosition());
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
});
holder.binding.actionButtonFavorite.setActiveImage(R.drawable.ic_round_star_24);

View file

@ -112,7 +112,7 @@ public class SuggestionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
holder.binding.followAction.setOnClickListener(v -> {
suggestionList.remove(position);
notifyItemRemoved(position);
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false);
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false, null);
});
holder.binding.notInterested.setOnClickListener(view -> {
suggestionList.remove(position);

View file

@ -602,21 +602,23 @@ public class AccountsVM extends AndroidViewModel {
/**
* Follow the given account. Can also be used to update whether to show reblogs or enable notifications.
*
* @param id The id of the account
* @param reblogs Receive this account's reblogs in home timeline? Defaults to true.
* @param notify Receive notifications when this account posts a status? Defaults to false.
* @param id The id of the account
* @param reblogs Receive this account's reblogs in home timeline? Defaults to true.
* @param notify Receive notifications when this account posts a status? Defaults to false.
* @param languages Filter received statuses for these languages.
* @return {@link LiveData} containing the {@link RelationShip} to the given account
*/
public LiveData<RelationShip> follow(@NonNull String instance, String token, @NonNull String id, boolean reblogs, boolean notify) {
public LiveData<RelationShip> follow(@NonNull String instance, String token, @NonNull String id, boolean reblogs, boolean notify, List<String> languages) {
relationShipMutableLiveData = new MutableLiveData<>();
MastodonAccountsService mastodonAccountsService = init(instance);
new Thread(() -> {
RelationShip relationShip = null;
Call<RelationShip> followCall = mastodonAccountsService.follow(token, id, reblogs, notify);
Call<RelationShip> followCall = mastodonAccountsService.follow(token, id, reblogs, notify, languages);
if (followCall != null) {
try {
Response<RelationShip> followResponse = followCall.execute();
if (followResponse.isSuccessful()) {
relationShip = followResponse.body();
}
} catch (Exception e) {

View file

@ -16,6 +16,11 @@
android:icon="@drawable/ic_baseline_open_with_24"
android:title="@string/action_open_in_web"
app:showAsAction="never" />
<item
android:id="@+id/action_subscribed_language"
android:icon="@drawable/ic_baseline_translate_24"
android:title="@string/action_change_subscribed_language"
app:showAsAction="never" />
<item
android:id="@+id/action_mute_home"
android:icon="@drawable/ic_baseline_volume_mute_24"

View file

@ -17,60 +17,98 @@
android:id="@+id/action_admin"
android:title="@string/administration"
app:showAsAction="never" />
<item
android:id="@+id/action_open_browser"
android:title="@string/action_open_in_web"
app:showAsAction="never" />
<item
android:id="@+id/action_pin"
android:title="@string/action_pin"
app:showAsAction="never" />
<item
android:id="@+id/action_share"
android:id="@+id/action_share_action"
android:title="@string/more_action_6"
app:showAsAction="never" />
app:showAsAction="never">
<menu>
<item
android:id="@+id/action_share"
android:title="@string/more_action_6"
app:showAsAction="never" />
<item
android:id="@+id/action_mention"
android:title="@string/more_action_7"
app:showAsAction="never" />
<item
android:id="@+id/action_open_browser"
android:title="@string/action_open_in_web"
app:showAsAction="never" />
<item
android:id="@+id/action_open_with"
android:title="@string/open_with_account"
app:showAsAction="never" />
<item
android:id="@+id/action_copy_link"
android:title="@string/copy_link"
app:showAsAction="never" />
<item
android:id="@+id/action_copy"
android:title="@string/more_action_5"
app:showAsAction="never" />
<item
android:id="@+id/action_custom_sharing"
android:title="@string/settings_title_custom_sharing"
android:visible="false"
app:showAsAction="never" />
</menu>
</item>
<item
android:id="@+id/action_custom_sharing"
android:title="@string/settings_title_custom_sharing"
android:visible="false"
app:showAsAction="never" />
<item
android:id="@+id/action_copy_link"
android:title="@string/copy_link"
app:showAsAction="never" />
<item
android:id="@+id/action_mute_conversation"
android:title="@string/mute_conversation"
app:showAsAction="never" />
<item
android:id="@+id/action_mute"
android:id="@+id/action_mute_menu"
android:title="@string/more_action_1"
app:showAsAction="never" />
app:showAsAction="never">
<menu>
<item
android:id="@+id/action_mute"
android:title="@string/more_action_1"
app:showAsAction="never" />
<item
android:id="@+id/action_mute_conversation"
android:title="@string/mute_conversation"
app:showAsAction="never" />
<item
android:id="@+id/action_mute_home"
android:title="@string/mute_home"
app:showAsAction="never" />
<item
android:id="@+id/action_timed_mute"
android:title="@string/more_action_8"
app:showAsAction="never" />
</menu>
</item>
<item
android:id="@+id/action_mute_home"
android:title="@string/mute_home"
app:showAsAction="never" />
<item
android:id="@+id/action_timed_mute"
android:title="@string/more_action_8"
app:showAsAction="never" />
android:id="@+id/action_block_menu"
android:title="@string/more_action_3"
app:showAsAction="never">
<menu>
<item
android:id="@+id/action_block"
android:title="@string/more_action_2"
app:showAsAction="never" />
<item
android:id="@+id/action_report"
android:title="@string/more_action_3"
app:showAsAction="never" />
<item
android:id="@+id/action_block_domain"
android:title="@string/block_domain"
app:showAsAction="never" />
</menu>
</item>
<item
android:id="@+id/action_schedule_boost"
android:title="@string/schedule_boost"
app:showAsAction="never" />
<item
android:id="@+id/action_block"
android:title="@string/more_action_2"
app:showAsAction="never" />
<item
android:id="@+id/action_report"
android:title="@string/more_action_3"
app:showAsAction="never" />
<item
android:id="@+id/action_block_domain"
android:title="@string/block_domain"
app:showAsAction="never" />
<item
android:id="@+id/action_redraft"
android:title="@string/more_action_9"
@ -79,16 +117,5 @@
android:id="@+id/action_remove"
android:title="@string/more_action_4"
app:showAsAction="never" />
<item
android:id="@+id/action_copy"
android:title="@string/more_action_5"
app:showAsAction="never" />
<item
android:id="@+id/action_mention"
android:title="@string/more_action_7"
app:showAsAction="never" />
<item
android:id="@+id/action_open_with"
android:title="@string/open_with_account"
app:showAsAction="never" />
</menu>

View file

@ -100,7 +100,7 @@
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="AppThemeAlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
<style name="AppThemeAlertDialog" parent="Theme.Material3.Dark.Dialog.Alert">
<item name="linkColor">@color/md_theme_dark_primary</item>
<item name="colorPrimary">@color/md_theme_dark_primary</item>
<item name="colorOnPrimary">@color/md_theme_dark_onPrimary</item>
@ -223,7 +223,7 @@
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="SolarizedAlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
<style name="SolarizedAlertDialog" parent="Theme.Material3.Dark.Dialog.Alert">
<item name="linkColor">@color/solarized_md_theme_dark_onPrimaryContainer</item>
<item name="colorPrimary">@color/solarized_md_theme_dark_primary</item>
<item name="colorOnPrimary">@color/solarized_md_theme_dark_onPrimary</item>
@ -339,7 +339,7 @@
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="BlackAlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
<style name="BlackAlertDialog" parent="Theme.Material3.Dark.Dialog.Alert">
<item name="linkColor">@color/black_200</item>
<item name="colorPrimary">@color/dracula_comment</item>
<item name="colorOnPrimary">@color/white</item>
@ -454,7 +454,7 @@
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="DraculaAlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
<style name="DraculaAlertDialog" parent="Theme.Material3.Dark.Dialog.Alert">
<item name="linkColor">@color/dracula_pink</item>
<item name="colorPrimary">@color/dracula_comment</item>
<item name="colorOnPrimary">@color/dracula_foreground</item>

View file

@ -2227,4 +2227,6 @@
<string name="set_maths_support">Write formula</string>
<string name="maths_format">Maths format</string>
<string name="hide_single_media_with_card">Hide single media when there is a link preview</string>
<string name="action_change_subscribed_language">Change subscribed languages</string>
<string name="filter_languages">Filter languages</string>
</resources>

View file

@ -100,7 +100,7 @@
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="AppThemeAlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
<style name="AppThemeAlertDialog" parent="Theme.Material3.Dark.Dialog.Alert">
<item name="linkColor">@color/md_theme_light_primary</item>
<item name="colorPrimary">@color/md_theme_light_primary</item>
<item name="colorOnPrimary">@color/md_theme_light_onPrimary</item>
@ -185,7 +185,7 @@
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="SolarizedAlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
<style name="SolarizedAlertDialog" parent="Theme.Material3.Dark.Dialog.Alert">
<item name="linkColor">@color/solarized_md_theme_light_primary</item>
<item name="colorPrimary">@color/solarized_md_theme_light_primary</item>
<item name="colorOnPrimary">@color/solarized_md_theme_light_onPrimary</item>

View file

@ -1,9 +1,11 @@
Added:
- Maths support (view and compose)
- Filter DMs in HOME (long press on the tab)
- Filter languages for users in home timeline (from their profile)
Changed:
- Hide single media with preview is now a setting (default: disabled)
- Group items in menu of messages
Fixed:
- Cross-actions didn't display account instances