diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 6a490eb2..57a3544c 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -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); diff --git a/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java b/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java index eeea8b6a..057bc3f0 100644 --- a/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java @@ -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))); + }); + } }); } diff --git a/app/src/main/java/app/fedilab/android/helper/MastodonHelper.java b/app/src/main/java/app/fedilab/android/helper/MastodonHelper.java index 65ba9802..cc0e78e7 100644 --- a/app/src/main/java/app/fedilab/android/helper/MastodonHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/MastodonHelper.java @@ -15,6 +15,8 @@ package app.fedilab.android.helper; * see . */ +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; + } } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index db2aba5e..25230ab3 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -712,12 +712,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 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 + android:layout_height="wrap_content"> - + android:scaleType="centerCrop" + tools:src="@tools:sample/backgrounds/scenic" /> - - - - - - - + - + + + + + + + + + + + - + \ No newline at end of file diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml index 4ab3fc40..ab161c77 100644 --- a/app/src/main/res/menu/activity_main_drawer.xml +++ b/app/src/main/res/menu/activity_main_drawer.xml @@ -3,74 +3,100 @@ xmlns:tools="http://schemas.android.com/tools" tools:showIn="navigation_view"> - + + + + + + + + + + + + + + + + + - - + - + + + + + android:id="@+id/nav_app" + android:title="@string/my_app"> + + + + + + + - + + + + - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml index cbdc7117..b1dda381 100644 --- a/app/src/main/res/menu/main.xml +++ b/app/src/main/res/menu/main.xml @@ -1,11 +1,8 @@ - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 05a4af2d..1177a0ff 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -922,6 +922,9 @@ REPLACE_WIKIPEDIA_HOST wikiless.org LAST_NOTIFICATION_ID + SET_MAX_INSTANCE_CHAR + + Type of notifications Chose the type of notifications Notification sounds @@ -982,6 +985,10 @@ Are you sure you want to delete cache? If you have drafts with media, the attached media will be lost. Use the default system language Language for messages + My instance + My app + My account + Set your max char count