Set instance max chars

This commit is contained in:
Thomas 2022-07-20 12:07:44 +02:00
parent 10e66a3e7e
commit 71aaaadccb
8 changed files with 235 additions and 123 deletions

View file

@ -516,6 +516,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
} else if (id == R.id.nav_cache) {
Intent intent = new Intent(BaseMainActivity.this, CacheActivity.class);
startActivity(intent);
} else if (id == R.id.nav_about_instance) {
Intent intent = new Intent(BaseMainActivity.this, InstanceActivity.class);
startActivity(intent);
}
binding.drawerLayout.close();
return false;
@ -677,10 +680,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
AlertDialog alert = alt_bld.create();
alert.show();
return true;
} else if (itemId == R.id.action_about_instance) {
Intent intent = new Intent(BaseMainActivity.this, InstanceActivity.class);
startActivity(intent);
return true;
} else if (itemId == R.id.action_proxy) {
Intent intent = new Intent(BaseMainActivity.this, ProxyActivity.class);
startActivity(intent);

View file

@ -16,6 +16,7 @@ package app.fedilab.android.activities;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -23,9 +24,9 @@ import android.text.Html;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
import com.bumptech.glide.Glide;
@ -35,13 +36,13 @@ import app.fedilab.android.client.entities.api.Instance;
import app.fedilab.android.databinding.ActivityInstanceBinding;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.InstancesVM;
import es.dmoral.toasty.Toasty;
public class InstanceActivity extends BaseActivity {
ActivityInstanceBinding binding;
private boolean applyMaxChar = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -54,8 +55,26 @@ public class InstanceActivity extends BaseActivity {
getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (getSupportActionBar() != null)
getSupportActionBar().hide();
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(InstanceActivity.this);
binding.close.setOnClickListener(
binding.close.setOnClickListener(view -> finish());
view -> {
if (applyMaxChar) {
String max_char = binding.maxChar.getText().toString();
SharedPreferences.Editor editor = sharedpreferences.edit();
if (!max_char.isEmpty()) {
try {
editor.putInt(getString(R.string.SET_MAX_INSTANCE_CHAR) + MainActivity.currentInstance, Integer.parseInt(max_char));
editor.apply();
} catch (Exception ignored) {
}
}
}
finish();
}
);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -66,33 +85,41 @@ public class InstanceActivity extends BaseActivity {
instancesVM.getInstance(BaseMainActivity.currentInstance).observe(InstanceActivity.this, instanceInfo -> {
binding.instanceContainer.setVisibility(View.VISIBLE);
binding.loader.setVisibility(View.GONE);
if (instanceInfo == null || instanceInfo.info == null) {
Toasty.error(InstanceActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
Instance instance = instanceInfo.info;
binding.instanceTitle.setText(instance.title);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
binding.instanceDescription.setText(Html.fromHtml(instance.description, Html.FROM_HTML_MODE_LEGACY));
else
binding.instanceDescription.setText(Html.fromHtml(instance.description));
if (instance.description == null || instance.description.trim().length() == 0)
binding.instanceDescription.setText(getString(R.string.instance_no_description));
binding.instanceVersion.setText(instance.version);
binding.instanceUri.setText(instance.uri);
if (instance.email == null) {
binding.instanceContact.hide();
}
Glide.with(InstanceActivity.this)
.asBitmap()
.load(instance.thumbnail)
.into(binding.backGroundImage);
binding.instanceContact.setOnClickListener(v -> {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", instance.email, null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "[Mastodon] - " + instance.uri);
startActivity(Intent.createChooser(emailIntent, getString(R.string.send_email)));
});
if (instanceInfo == null || instanceInfo.info == null || instanceInfo.info.description == null) {
binding.maxCharContainer.setVisibility(View.VISIBLE);
binding.instanceContainer.setVisibility(View.GONE);
int val = sharedpreferences.getInt(getString(R.string.SET_MAX_INSTANCE_CHAR) + MainActivity.currentInstance, -1);
if (val != -1) {
binding.maxChar.setText(String.valueOf(val));
}
applyMaxChar = true;
} else {
Instance instance = instanceInfo.info;
binding.instanceTitle.setText(instance.title);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
binding.instanceDescription.setText(Html.fromHtml(instance.description, Html.FROM_HTML_MODE_LEGACY));
else
binding.instanceDescription.setText(Html.fromHtml(instance.description));
if (instance.description == null || instance.description.trim().length() == 0)
binding.instanceDescription.setText(getString(R.string.instance_no_description));
binding.instanceVersion.setText(instance.version);
binding.instanceUri.setText(instance.uri);
if (instance.email == null) {
binding.instanceContact.hide();
}
Glide.with(InstanceActivity.this)
.asBitmap()
.load(instance.thumbnail)
.into(binding.backGroundImage);
binding.instanceContact.setOnClickListener(v -> {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", instance.email, null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "[Mastodon] - " + instance.uri);
startActivity(Intent.createChooser(emailIntent, getString(R.string.send_email)));
});
}
});
}

View file

@ -15,6 +15,8 @@ package app.fedilab.android.helper;
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.instanceInfo;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
@ -51,6 +53,7 @@ import java.util.regex.Pattern;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.client.entities.api.Account;
import app.fedilab.android.client.entities.api.Pagination;
import app.fedilab.android.client.entities.api.RelationShip;
@ -499,4 +502,19 @@ public class MastodonHelper {
void onTimedMute(RelationShip relationShip);
}
public static int getInstanceMaxChars(Context context) {
int max_car;
if (instanceInfo != null) {
max_car = instanceInfo.max_toot_chars != null ? Integer.parseInt(instanceInfo.max_toot_chars) : instanceInfo.configuration.statusesConf.max_characters;
} else {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
int val = sharedpreferences.getInt(context.getString(R.string.SET_MAX_INSTANCE_CHAR) + MainActivity.currentInstance, -1);
if (val != -1) {
return val;
} else {
max_car = 500;
}
}
return max_car;
}
}

View file

@ -712,12 +712,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
public void afterTextChanged(Editable s) {
int currentLength = MastodonHelper.countLength(holder);
//Copy/past
int max_car;
if (instanceInfo != null) {
max_car = instanceInfo.max_toot_chars != null ? Integer.parseInt(instanceInfo.max_toot_chars) : instanceInfo.configuration.statusesConf.max_characters;
} else {
max_car = 500;
}
int max_car = MastodonHelper.getInstanceMaxChars(context);
if (currentLength > max_car + 1) {
int from = max_car - holder.binding.contentSpoiler.getText().length();
int to = (currentLength - holder.binding.contentSpoiler.getText().length());
@ -1246,7 +1241,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
if (instanceInfo == null) {
return;
}
int max_car = instanceInfo.max_toot_chars != null ? Integer.parseInt(instanceInfo.max_toot_chars) : instanceInfo.configuration.statusesConf.max_characters;
int max_car = MastodonHelper.getInstanceMaxChars(context);
holder.binding.characterProgress.setMax(max_car);
holder.binding.contentSpoiler.addTextChangedListener(new TextWatcher() {
private int cPosition;

View file

@ -16,10 +16,11 @@
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="350dp">
android:layout_height="wrap_content">
<RelativeLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/fab_margin"
@ -28,25 +29,31 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:alpha="0.2">
<ImageView
android:id="@+id/back_ground_image"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_height="match_parent"
android:contentDescription="@string/logo_of_the_instance"
android:scaleType="centerCrop" />
android:scaleType="centerCrop"
tools:src="@tools:sample/backgrounds/scenic" />
</RelativeLayout>
<LinearLayout
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_height="wrap_content"
android:id="@+id/instance_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="20dp"
android:orientation="vertical">
<!-- Instance title -->
<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/instance_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -55,7 +62,7 @@
android:textSize="20sp" />
<!-- Instance description -->
<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/instance_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -64,7 +71,7 @@
android:gravity="center_horizontal"
android:textSize="16sp" />
<LinearLayout
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -72,7 +79,7 @@
android:gravity="center"
android:orientation="horizontal">
<!-- Instance version -->
<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/instance_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -80,7 +87,7 @@
android:textSize="14sp"
android:textStyle="italic" />
<!-- Instance URI -->
<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/instance_uri"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -88,7 +95,7 @@
android:gravity="center_horizontal"
android:textSize="14sp"
android:textStyle="italic" />
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/instance_contact"
@ -99,13 +106,45 @@
android:contentDescription="@string/contact_instance_admin"
android:src="@drawable/ic_baseline_mail_outline_24"
app:backgroundTint="@color/cyanea_accent_dark_reference" />
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/max_char_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@+id/instance_container"
tools:visibility="visible">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_your_max_char_count"
android:textSize="18sp" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/max_char"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:hint="500"
android:inputType="number"
android:textSize="18sp"
tools:ignore="HardcodedText" />
</androidx.appcompat.widget.LinearLayoutCompat>
<!-- Main Loader -->
<RelativeLayout
android:id="@+id/loader"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:visibility="visible"
android:visibility="gone">
<ProgressBar
@ -115,6 +154,10 @@
</RelativeLayout>
<androidx.appcompat.widget.AppCompatButton
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/max_char_container"
android:id="@+id/close"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
@ -127,5 +170,5 @@
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="16sp" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View file

@ -3,74 +3,100 @@
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<group>
<item
android:id="@+id/nav_main_com"
android:title="@string/my_account">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_drafts"
android:icon="@drawable/ic_baseline_drafts_24"
android:title="@string/drafts" />
<item
android:id="@+id/nav_interactions"
android:icon="@drawable/ic_baseline_supervised_user_circle_24"
android:title="@string/interactions" />
<item
android:id="@+id/nav_filter"
android:icon="@drawable/ic_baseline_filter_list_24"
android:title="@string/filters" />
<item
android:id="@+id/nav_list"
android:icon="@drawable/ic_baseline_view_list_24"
android:title="@string/action_lists" />
<item
android:id="@+id/nav_follow_requests"
android:icon="@drawable/ic_baseline_group_add_24"
android:title="@string/follow_request"
android:visible="false" />
<item
android:id="@+id/nav_administration"
android:icon="@drawable/ic_baseline_admin_panel_settings_24"
android:title="@string/administration"
android:visible="false" />
</group>
</menu>
</item>
<item
android:id="@+id/nav_instance"
android:title="@string/my_instance">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_announcements"
android:icon="@drawable/ic_baseline_message_24"
android:title="@string/action_announcements"
android:visible="true" />
<item
android:id="@+id/nav_drafts"
android:icon="@drawable/ic_baseline_drafts_24"
android:title="@string/drafts" />
<item
android:id="@+id/nav_reorder"
android:icon="@drawable/ic_baseline_reorder_24"
android:title="@string/reorder_timelines" />
<item
android:id="@+id/nav_trends"
android:icon="@drawable/ic_baseline_trending_up_24"
android:title="@string/trending"
android:visible="true" />
<item
android:id="@+id/nav_interactions"
android:icon="@drawable/ic_baseline_supervised_user_circle_24"
android:title="@string/interactions" />
<item
android:id="@+id/nav_about_instance"
android:icon="@drawable/ic_info_outline_white_24dp"
android:title="@string/action_about_instance"
android:visible="true" />
</group>
</menu>
</item>
<item
android:id="@+id/nav_filter"
android:icon="@drawable/ic_baseline_filter_list_24"
android:title="@string/filters" />
android:id="@+id/nav_app"
android:title="@string/my_app">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_reorder"
android:icon="@drawable/ic_baseline_reorder_24"
android:title="@string/reorder_timelines" />
<item
android:id="@+id/nav_scheduled"
android:icon="@drawable/ic_baseline_schedule_24"
android:title="@string/scheduled" />
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_baseline_settings_24"
android:title="@string/settings" />
<item
android:id="@+id/nav_cache"
android:icon="@drawable/ic_baseline_cached_24"
android:title="@string/action_cache" />
<item
android:id="@+id/nav_about"
android:icon="@drawable/ic_baseline_info_24"
android:title="@string/action_about" />
<item
android:id="@+id/nav_list"
android:icon="@drawable/ic_baseline_view_list_24"
android:title="@string/action_lists" />
<item
android:id="@+id/nav_partnership"
android:icon="@drawable/ic_baseline_account_circle_24"
android:title="@string/action_partnership" />
</group>
</menu>
</item>
<item
android:id="@+id/nav_announcements"
android:icon="@drawable/ic_baseline_message_24"
android:title="@string/action_announcements"
android:visible="true" />
<item
android:id="@+id/nav_trends"
android:icon="@drawable/ic_baseline_trending_up_24"
android:title="@string/trending"
android:visible="true" />
<item
android:id="@+id/nav_scheduled"
android:icon="@drawable/ic_baseline_schedule_24"
android:title="@string/scheduled" />
<item
android:id="@+id/nav_follow_requests"
android:icon="@drawable/ic_baseline_group_add_24"
android:title="@string/follow_request"
android:visible="false" />
<item
android:id="@+id/nav_administration"
android:icon="@drawable/ic_baseline_admin_panel_settings_24"
android:title="@string/administration"
android:visible="false" />
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_baseline_settings_24"
android:title="@string/settings" />
<item
android:id="@+id/nav_cache"
android:icon="@drawable/ic_baseline_cached_24"
android:title="@string/action_cache" />
<item
android:id="@+id/nav_about"
android:icon="@drawable/ic_baseline_info_24"
android:title="@string/action_about" />
<item
android:id="@+id/nav_partnership"
android:icon="@drawable/ic_baseline_account_circle_24"
android:title="@string/action_partnership" />
</group>
</menu>

View file

@ -1,11 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_about_instance"
android:title="@string/action_about_instance"
app:showAsAction="never" />
<item
<item
android:id="@+id/action_proxy"
android:title="@string/proxy_set"
app:showAsAction="never" />

View file

@ -922,6 +922,9 @@
<string name="REPLACE_WIKIPEDIA_HOST" translatable="false">REPLACE_WIKIPEDIA_HOST</string>
<string name="DEFAULT_REPLACE_WIKIPEDIA_HOST" translatable="false">wikiless.org</string>
<string name="LAST_NOTIFICATION_ID" translatable="false">LAST_NOTIFICATION_ID</string>
<string name="SET_MAX_INSTANCE_CHAR" translatable="false">SET_MAX_INSTANCE_CHAR</string>
<string name="type_of_notifications">Type of notifications</string>
<string name="type_of_notifications_title">Chose the type of notifications</string>
<string name="notification_sounds">Notification sounds</string>
@ -982,6 +985,10 @@
<string name="delete_cache_message">Are you sure you want to delete cache? If you have drafts with media, the attached media will be lost.</string>
<string name="default_system_language">Use the default system language</string>
<string name="message_language">Language for messages</string>
<string name="my_instance">My instance</string>
<string name="my_app">My app</string>
<string name="my_account">My account</string>
<string name="set_your_max_char_count">Set your max char count</string>
<string-array name="photo_editor_emoji" translatable="false">
<!-- Smiles -->